<!doctype html>
<html itemscope itemtype="http://schema.org/WebPage" lang="zh-cn" class="no-js">
  <head>
    <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="generator" content="Hugo 0.121.1">
<link rel="canonical" type="text/html" href="/docs/">
<meta name="robots" content="noindex, nofollow">


<link rel="shortcut icon" href="/favicons/favicon.ico" >
<link rel="apple-touch-icon" href="/favicons/apple-touch-icon-180x180.png" sizes="180x180">
<link rel="icon" type="image/png" href="/favicons/favicon-16x16.png" sizes="16x16">
<link rel="icon" type="image/png" href="/favicons/favicon-32x32.png" sizes="32x32">
<link rel="icon" type="image/png" href="/favicons/android-36x36.png" sizes="36x36">
<link rel="icon" type="image/png" href="/favicons/android-48x48.png" sizes="48x48">
<link rel="icon" type="image/png" href="/favicons/android-72x72.png" sizes="72x72">
<link rel="icon" type="image/png" href="/favicons/android-96x96.png" sizes="96x96">
<link rel="icon" type="image/png" href="/favicons/android-144x144.png" sizes="144x144">
<link rel="icon" type="image/png" href="/favicons/android-192x192.png" sizes="192x192">

<title>产品文档 | SOFAServerless</title>
<meta name="description" content="">
<meta property="og:title" content="产品文档" />
<meta property="og:description" content="" />
<meta property="og:type" content="website" />
<meta property="og:url" content="/docs/" />

<meta itemprop="name" content="产品文档">
<meta itemprop="description" content=""><meta name="twitter:card" content="summary"/><meta name="twitter:title" content="产品文档"/>
<meta name="twitter:description" content=""/>




<link rel="preload" href="/scss/main.min.526354c4efc1a4747972ed64c3be00f7db62aec5f0a3e6ae42052f97e2675d86.css" as="style">
<link href="/scss/main.min.526354c4efc1a4747972ed64c3be00f7db62aec5f0a3e6ae42052f97e2675d86.css" rel="stylesheet" integrity="">

<script
  src="https://code.jquery.com/jquery-3.6.3.min.js"
  integrity="sha512-STof4xm1wgkfm7heWqFJVn58Hm3EtS31XFaagaa8VMReCXAkQnJZ+jEy8PCC/iT18dFy95WcExNHFTqLyp72eQ=="
  crossorigin="anonymous"></script>
<link rel="stylesheet" href="/css/prism.css"/>
<link href="/img/logo.svg" rel="icon" type="image/svg">
<link href="/search/pagefind-ui.css" rel="stylesheet">
<script src="/search/pagefind-ui.js" type="text/javascript"></script>

<script>
    window.addEventListener('DOMContentLoaded', (event) => {
        new PagefindUI({ element: ".td-search" });
    });
</script>


<script>
var doNotTrack = false;
if (!doNotTrack) {
	window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
	ga('create', 'G-DZ8Q3F0GZ7', 'auto');
	
	ga('send', 'pageview');
}
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>

<script async src="https://www.googletagmanager.com/gtag/js?id=G-DZ8Q3F0GZ7"></script>
<script>
var doNotTrack = false;
if (!doNotTrack) {
	window.dataLayer = window.dataLayer || [];
	function gtag(){dataLayer.push(arguments);}
	gtag('js', new Date());
	gtag('config', 'G-DZ8Q3F0GZ7');
}
</script>
  </head>
  <body class="td-section">
    <header>
      <nav class="td-navbar navbar-dark js-navbar-scroll">
<div class="container-fluid flex-column flex-md-row">
  <a class="navbar-brand" href="/"><span class="navbar-brand__logo navbar-logo"><svg width="26" height="29" viewBox="0 0 26 29" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><defs><linearGradient x1="52.6662558%" y1="95.7312514%" x2="35.7492678%" y2="11.0078657%" id="linearGradient-wxw43fh1xd-1"><stop stop-color="#9822e4" offset="0"/><stop stop-color="#e643fa" offset="86.0585504%"/><stop stop-color="#f876ff" offset="100%"/></linearGradient><path d="M15.9275871 1.54432572 15.936122 1.5594269 15.9445709 1.57457632 5.01248933 7.79418913 7.699 9.304l8.8412359-4.72420311.8668497-.49490764C17.4171462 4.0791454 17.4272394 4.07345885 17.4373647 4.06782987c1.474137-.81952243 3.3335154-.28885241 4.1530379 1.18528466L10.875 11.088l2.864 1.609 8.843271-5.6213813c1.1038914-.6292563 2.5021428-.23250173 3.1230817.88617614C25.8984381 8.30965565 25.9998668 8.70204694 25.9998668 9.10116416V19.9436637c0 1.3476373-1.002317 2.484932-2.3392704 2.6542897L22.9421516 22.6889619V10.4257286L20.457252 12.0257475 20.457758 23.6880152c0 1.2665471-1.0267393 2.2932864-2.2932864 2.2932864H17.59115L17.590252 13.8727475 15.106 15.473 15.1067564 27.0588825c0 1.0695936-.855616100000001 1.9366704-1.911072 1.9366704C12.8696714 28.9955529 12.5490782 28.9110348 12.2643947 28.7500365L1.63270516 23.3171586C.159863707 22.5645249-.423980046 20.7604209.328653641 19.2875794L.372104915 19.2057013 12.0490412 25.0797183 12.049 22.086 1.98952173 16.7675786C.51279311 15.9867912-.0513787599 14.1567129.729408593 12.6799843L.744416289 12.6519572.759717752 12.6240895 12.049 18.593 12.0490412 15.2566254 1.7391964 9.45898637C1.44132502 9.2850324 1.19527431 9.0328708 1.02697438 8.72907568c-.516688418-.93266477-.189466545-2.11320819.7308705-2.63681754C6.19445786 3.56812633 9.52191759 1.67502747 11.7402241.412961569L11.7628911.400065593c1.4660277-.834070345 3.3306257-.321767634 4.164696 1.144260127z" id="path-wxw43fh1xd-2"/><linearGradient x1="50.6099966%" y1="31.6743333%" x2="50.2419846%" y2="73.0702907%" id="linearGradient-wxw43fh1xd-4"><stop stop-color="#8200b5" offset="0"/><stop stop-color="#8200b5" stop-opacity="0" offset="100%"/></linearGradient><linearGradient x1="50.6028666%" y1="31.6743333%" x2="50.2391561%" y2="73.0702907%" id="linearGradient-wxw43fh1xd-5"><stop stop-color="#8200b5" offset="0"/><stop stop-color="#8200b5" stop-opacity="0" offset="100%"/></linearGradient><linearGradient x1="90.8235257%" y1="50%" x2="3.24041867%" y2="52.9415572%" id="linearGradient-wxw43fh1xd-6"><stop stop-color="#dd3ff7" stop-opacity="0" offset="0"/><stop stop-color="#ca23e4" offset="100%"/></linearGradient><linearGradient x1="74.3272776%" y1="35.8586031%" x2="19.6895996%" y2="19.3309621%" id="linearGradient-wxw43fh1xd-7"><stop stop-color="#b800d1" stop-opacity="0" offset="0"/><stop stop-color="#ae00c5" offset="100%"/></linearGradient><linearGradient x1="97.0070676%" y1="71.8003287%" x2="11.3661868%" y2="30.5044309%" id="linearGradient-wxw43fh1xd-8"><stop stop-color="#940ec7" offset="0"/><stop stop-color="#c435f0" stop-opacity="0" offset="100%"/></linearGradient></defs><g id="页面-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><g id="首页" transform="translate(-24.000000, -18.000000)"><g id="编组-4" transform="translate(24.000133, 16.000000)"><g id="路径-6-copy-2" transform="translate(0.000000, 2.004447)"><mask id="mask-wxw43fh1xd-3" fill="#fff"><use xlink:href="#path-wxw43fh1xd-2"/></mask><use id="Mask" fill="url(#linearGradient-wxw43fh1xd-1)" fill-rule="nonzero" xlink:href="#path-wxw43fh1xd-2"/><path d="M12.0490412 15.2684078 13.03943 15.5167092C14.3279076 16.0478608 15.1686754 17.3038563 15.1686754 18.6975193V18.7421449v9.047164l-3.1196342-1.4070083V15.2684078z" id="Path-114-Copy-2" fill="url(#linearGradient-wxw43fh1xd-4)" opacity=".69047619" mask="url(#mask-wxw43fh1xd-3)"/><path d="M22.9421516 10.4227424 23.8594661 10.2542707C24.8889759 10.219744 25.7876765 10.946368 25.9694916 11.9602841L26.0763097 12.5559692 26.0617858 22.9064645l-3.1196342-1.4070082V10.4227424z" id="Path-114-Copy-2" fill="url(#linearGradient-wxw43fh1xd-5)" opacity=".69047619" mask="url(#mask-wxw43fh1xd-3)"/><polygon id="Path-41" fill="url(#linearGradient-wxw43fh1xd-6)" mask="url(#mask-wxw43fh1xd-3)" points="7.6326499 9.31647968 11.9297751 6.77228295 14.9765833 9.31647968 10.7681311 11.1500753"/><path d="M6.16852974 12.7326226C8.05429918 13.6181711 7.86496926 14.83948 8.18831704 15.006813 8.70089861 15.2720748 9.14143095 17.098905 9.86115602 17.1695013 10.6949216 17.2512836 11.6478081 10.8552079 10.3936906 10.4556578 9.48069361 10.1647855 7.32719679 9.49121213 3.93320016 8.43493769c-.63204609 1.86851711.11306377 3.30107871 2.23532958 4.29768491z" fill="url(#linearGradient-wxw43fh1xd-7)" mask="url(#mask-wxw43fh1xd-3)" transform="translate(7.357416, 12.802608) rotate(-347.000000) translate(-7.357416, -12.802608)"/><polygon id="Path-43" fill="url(#linearGradient-wxw43fh1xd-8)" mask="url(#mask-wxw43fh1xd-3)" points="12.0699788 18.5615749 6.27140769 15.1359473 5.30588708 19.0963147 12.0699788 22.1120507"/></g></g></g></g></svg></span><span class="navbar-brand__name">SOFAServerless</span></a>
  <div class="td-navbar-nav-scroll ms-md-auto" id="main_navbar">
    <ul class="navbar-nav">
      <li class="nav-item">
        <a class="nav-link" href="/home/"><span>首页</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link active" href="/docs/"><span>产品文档</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="/blog/"><span>最新信息</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="/community/"><span>参与社区</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="/user-cases/"><span>用户案例</span></a>
      </li>
      <li class="nav-item dropdown d-none d-lg-block">
        <div class="dropdown">
  <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">中文</a>
  <ul class="dropdown-menu">
    <li><a class="dropdown-item" href="/no/"></a></li>
    </ul>
</div></li>
      </ul>
  </div>
  <div class="d-none d-lg-block">
    <div class="td-search">
  <div class="td-search__icon"></div>
  <input type="search" class="td-search__input form-control td-search-input" placeholder="站内搜索…" aria-label="站内搜索…" autocomplete="off">
</div>

  </div>
</div>
</nav>
    </header>
    <div class="container-fluid td-outer">
      <div class="td-main">
        <div class="row flex-xl-nowrap">
          <main class="col-12 col-md-9 col-xl-8 ps-md-5" role="main">
            




<div class="td-content">
<div class="pageinfo pageinfo-primary d-print-none">
<p>
这是本节的多页打印视图。
<a href="#" onclick="print();return false;">点击此处打印</a>.
</p><p>
<a href="/docs/">返回本页常规视图</a>.
</p>
</div>



<h1 class="title">产品文档</h1>





    <ul>
    
  
  
  
  

  
    
    
	
<li>1: <a href="#pg-d1742b0a409facb9dc9b2828826c6df3">产品介绍</a></li>


    
    <ul>
        
  
  
  
  

  
    
    
	
<li>1.1: <a href="#pg-fd977b0af51d1a489a61551eb5e32610">简介与适用场景</a></li>


    
  
    
    
	
<li>1.2: <a href="#pg-3a89b12892834b585df4690bf050d9d5">行业背景</a></li>


    
  
    
    
	
<li>1.3: <a href="#pg-1a655298f9f51d3790e457c666fd9032">架构介绍</a></li>


    
    <ul>
        
  
  
  
  

  
    
    
	
<li>1.3.1: <a href="#pg-eae697a827c518b3c38ed9ee18d3ff71">架构原理</a></li>


    
  
    
    
	
<li>1.3.2: <a href="#pg-f3857e8be17ade9a35d641cc483d619b">基座与模块间类委托加载原理介绍</a></li>


    
  

    </ul>
    
  

    </ul>
    
  
    
    
	
<li>2: <a href="#pg-6546478d87b4368b79e83eb0e32c466c">快速开始</a></li>


    
    <ul>
        
  
  
  
  

  

    </ul>
    
  
    
    
	
<li>3: <a href="#pg-cd27d705d8e87ceae329f27f89a34cef">视频教程</a></li>


    
    <ul>
        
  
  
  
  

  

    </ul>
    
  
    
    
	
<li>4: <a href="#pg-68ec2370d0409cc27325be36693f9368">用户手册</a></li>


    
    <ul>
        
  
  
  
  

  
    
    
	
<li>4.1: <a href="#pg-85d651fc55ba7dc800d677008a2c7fa5">基座接入</a></li>


    
    <ul>
        
  
  
  
  

  
    
    
	
<li>4.1.1: <a href="#pg-18b872e057bed8156d471e220e894432">SpringBoot 或 SOFABoot 升级为基座</a></li>


    
  

    </ul>
    
  
    
    
	
<li>4.2: <a href="#pg-144d016bb7fc7652017580bd4bbe4e56">模块接入</a></li>


    
    <ul>
        
  
  
  
  

  
    
    
	
<li>4.2.1: <a href="#pg-efab46696dc71baece82293194586ad3">SpringBoot 或 SOFABoot 一键升级为模块</a></li>


    
  
    
    
	
<li>4.2.2: <a href="#pg-0f5b7bcef23427d2a6a0c1fcaca9ad4a">使用 maven archtype 脚手架自动生成</a></li>


    
  

    </ul>
    
  
    
    
	
<li>4.3: <a href="#pg-386a856dc258ab2701435ac4609b80fe">基座与模块并行开发验证</a></li>


    
  
    
    
	
<li>4.4: <a href="#pg-1338dd6d363fcbe1552c858a20719417">模块研发</a></li>


    
    <ul>
        
  
  
  
  

  
    
    
	
<li>4.4.1: <a href="#pg-bf65e93b734e75f456eb02447ae9f065">编码规范</a></li>


    
  
    
    
	
<li>4.4.2: <a href="#pg-6e3cbd7799f1397ab7793638f56a6f1a">模块瘦身</a></li>


    
  
    
    
	
<li>4.4.3: <a href="#pg-66b2590d54145be7fd0f895684bc34ef">模块与模块、模块与基座通信</a></li>


    
  
    
    
	
<li>4.4.4: <a href="#pg-e829d04a9debc230b4d695f03971b67b">模块本地开发</a></li>


    
  
    
    
	
<li>4.4.5: <a href="#pg-28a800d400556ead949da2297e04f900">模块测试</a></li>


    
  
    
    
	
<li>4.4.6: <a href="#pg-037484c6b7708a4128ecdd19d8578aaa">复用基座拦截器</a></li>


    
  
    
    
	
<li>4.4.7: <a href="#pg-06ace3863ce3b10117de52a241f0d9e0">复用基座数据源</a></li>


    
  
    
    
	
<li>4.4.8: <a href="#pg-4a763f2560193bc6f6a4c64874383f22">静态合并部署</a></li>


    
  
    
    
	
<li>4.4.9: <a href="#pg-dbe415e386e1bcdf1f3e7a62a91e6eb6">模块中官方支持的中间件客户端</a></li>


    
  
    
    
	
<li>4.4.10: <a href="#pg-4c134980130d1dc3c830b9224a754361">SOFAArk 关键用户文档</a></li>


    
  

    </ul>
    
  
    
    
	
<li>4.5: <a href="#pg-307f45cbc34bd56c2422e01b460303bb">模块运维</a></li>


    
    <ul>
        
  
  
  
  

  
    
    
	
<li>4.5.1: <a href="#pg-f274515d3bf16798aa419325f53c707a">模块上线与下线</a></li>


    
  
    
    
	
<li>4.5.2: <a href="#pg-7b5bd50a9b9adfe3d8e27a3a4117e738">模块发布</a></li>


    
  
    
    
	
<li>4.5.3: <a href="#pg-03f7fcbe7eb355b82c98153891be1e48">基座和模块不兼容发布</a></li>


    
  
    
    
	
<li>4.5.4: <a href="#pg-ac1464ebc2e0083dd90ccb0c00118fca">模块扩缩容与替换</a></li>


    
  
    
    
	
<li>4.5.5: <a href="#pg-7011e375d7565bd7cea7f9347f8e8c9e">模块发布运维策略</a></li>


    
  
    
    
	
<li>4.5.6: <a href="#pg-24eb3a9c0234e21473eec787d4ae6d7a">独立使用 Arklet</a></li>


    
  
    
    
	
<li>4.5.7: <a href="#pg-c588ae48a684af6c4c57ee4d9aae6ce4">模块信息查看</a></li>


    
  
    
    
	
<li>4.5.8: <a href="#pg-cbb99adb1eb306a588e034d68e0481d8">模块Service</a></li>


    
  
    
    
	
<li>4.5.9: <a href="#pg-68c3bb9b1561f186515e61704fac5511">所有 K8S 资源定义及部署方式</a></li>


    
  

    </ul>
    
  

    </ul>
    
  
    
    
	
<li>5: <a href="#pg-99a93ef9534d11fef4be3e4b3b1a6381">参与社区</a></li>


    
    <ul>
        
  
  
  
  

  
    
    
	
<li>5.1: <a href="#pg-e29f40edf90bd16bb849d278394baf42">开放包容理念</a></li>


    
  
    
    
	
<li>5.2: <a href="#pg-602e76c3bdfe995632399d8611c22fa3">交流渠道</a></li>


    
  
    
    
	
<li>5.3: <a href="#pg-a473df27e2a59f4a48f7ec005f1be08d">贡献社区</a></li>


    
    <ul>
        
  
  
  
  

  
    
    
	
<li>5.3.1: <a href="#pg-2116f3408dfc680cc19d506d77f5894a">本地开发测试</a></li>


    
  
    
    
	
<li>5.3.2: <a href="#pg-5726ff7fce2c3ff40a2cd82591c376cc">完成第一次 PR 提交</a></li>


    
  
    
    
	
<li>5.3.3: <a href="#pg-6c5458a163d621b3a719a2d5b3973530">文档、Issue、流程贡献</a></li>


    
  
    
    
	
<li>5.3.4: <a href="#pg-d890a1e9140aca7ee684208abba11a5f">组织会议和运营布道</a></li>


    
  

    </ul>
    
  
    
    
	
<li>5.4: <a href="#pg-20720f61569788d3fa4a197db902e640">社区角色与晋升</a></li>


    
  
    
    
	
<li>5.5: <a href="#pg-00e955e7b325b37beabf9dc83947c176">SOFAArk 技术文档</a></li>


    
    <ul>
        
  
  
  
  

  

    </ul>
    
  
    
    
	
<li>5.6: <a href="#pg-9ae993d6fa8ac20662cf30a0e33bd534">Arklet 技术文档</a></li>


    
    <ul>
        
  
  
  
  

  
    
    
	
<li>5.6.1: <a href="#pg-44f8de035a733443de71918dd607b8ae">Arklet 架构设计与接口设计</a></li>


    
  
    
    
	
<li>5.6.2: <a href="#pg-ca0da12fe622ea86b46a675b1cf7ff9e">如何发布 Arklet 版本</a></li>


    
  

    </ul>
    
  
    
    
	
<li>5.7: <a href="#pg-9f7246557f3988e5591410a2c92f379e">ModuleController 技术文档</a></li>


    
    <ul>
        
  
  
  
  

  
    
    
	
<li>5.7.1: <a href="#pg-72b8455792d08674da639fa21b8e66ae">ModuleController 架构设计</a></li>


    
  
    
    
	
<li>5.7.2: <a href="#pg-be4b5c4491d910c089a03f3bd6b4ec7b">CRD 模型设计</a></li>


    
  
    
    
	
<li>5.7.3: <a href="#pg-339ad39102ec6d572f675d168eb0a6c2">核心代码结构</a></li>


    
  
    
    
	
<li>5.7.4: <a href="#pg-de7e40f637d5e11c931b8c9e41910f4d">模块生命周期</a></li>


    
  
    
    
	
<li>5.7.5: <a href="#pg-4c6a73428cd292db6a65b7e3740abdd4">核心流程时序图</a></li>


    
  

    </ul>
    
  
    
    
	
<li>5.8: <a href="#pg-db0fd3436760ca9f36ce5775358861d3">Arkctl 技术文档</a></li>


    
    <ul>
        
  
  
  
  

  
    
    
	
<li>5.8.1: <a href="#pg-17a1474bf0b4f08b2afd73c908fb081d">Arkctl 技术文档</a></li>


    
  

    </ul>
    
  
    
    
	
<li>5.9: <a href="#pg-c5379127fb28ac273198b2c05d133831">多模块运行时适配或最佳实践</a></li>


    
    <ul>
        
  
  
  
  

  
    
    
	
<li>5.9.1: <a href="#pg-e8336cb2ec84a57eea63b09a2d517063">log4j2 的多模块化适配</a></li>


    
  
    
    
	
<li>5.9.2: <a href="#pg-fce299658e201c9a561eaab5974c0199">ehcache 的多模块化最佳实践</a></li>


    
  

    </ul>
    
  

    </ul>
    
  
    
    
	
<li>6: <a href="#pg-4588103fb9a692533044ee756a5f863f">常见 FAQ</a></li>


    
    <ul>
        
  
  
  
  

  
    
    
	
<li>6.1: <a href="#pg-b0aca01070f80bb35c361f0308eb0170">常见问题列表</a></li>


    
  
    
    
	
<li>6.2: <a href="#pg-d12744cdebcd9160176b435785ebf207">如果模块独立引入 SpringBoot 框架部分会怎样？</a></li>


    
  

    </ul>
    
  

    </ul>


<div class="content">
      <script>
    window.location="/docs/introduction/intro-and-scenario/";
</script>

</div>
</div>


  
  
  
  

  
  

  
    
    
	
    

<div class="td-content" style="">
    
	<h1 id="pg-d1742b0a409facb9dc9b2828826c6df3">1 - 产品介绍</h1>
    
	
</div>



    
      
  
  
  
  

  
  

  
    
    
	
    

<div class="td-content" style="">
    
	<h1 id="pg-fd977b0af51d1a489a61551eb5e32610">1.1 - 简介与适用场景</h1>
    
	<h1 id="简介">简介</h1>
<p>SOFAServerless 是一种模块化的 Serverless 技术解决方案，它能让普通应用以比较低的代价演进为 Serverless 研发模式，让代码与资源解耦，轻松独立维护，与此同时支持秒级构建部署、合并部署、动态伸缩等能力为用户提供极致的研发运维体验，最终帮助企业实现降本增效。<br />随着各行各业的信息化数字化转型，企业面临越来越多的研发效率、协作效率、资源成本和服务治理痛点，接下来带领大家逐一体验这些痛点，以及它们在 SOFAServerless 中是如何被解决的。</p>
<h1 id="适用场景">适用场景</h1>
<h2 id="痛点-1应用构建发布慢或者-sdk-升级繁琐">痛点 1：应用构建发布慢或者 SDK 升级繁琐</h2>
<p>传统应用镜像化构建一般要 3 - 5 分钟，单机代码发布到启动完成也要 3 - 5 分钟，开发者每次验证代码修改或上线代码修改，都需要经历<strong>数次 6 - 10 分钟</strong>的构建发布等待，严重影响开发效率。此外，每次 SDK 升级（比如中间件框架、rpc、logging、json 等），都需要修改所有应用代码并重新构建发布，对开发者也造成了不必要的打扰。<br />通过使用 <strong>SOFAServerless</strong> <strong>通用基座</strong>与配套工具，您可以低成本的将应用切分为 “<strong>基座</strong>” 与 “<strong>模块</strong>”，其中基座沉淀了公司或者某个业务部门的公共 SDK，基座升级可以由专人负责，对业务开发者无感，业务开发者只需要编写模块。在我们目前支持的 Java 技术栈中，模块就是一个 SpringBoot 应用代码包（FatJar），只不过 SpringBoot 框架本身和其他的企业公共依赖在运行时会让基座提前加载预热，模块每次发布都会找一台预热 SpringBoot 的基座进行热部署，整个过程类似 AppEngine，能够帮用户实现应用 <strong>10 秒级构建发布</strong>和<strong>公共 SDK 升级无感</strong>。</p>
<img width="800px" src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/671/1694592240984-8ea49823-ebd0-4bb7-909c-380f0439382b.png#clientId=u0d56718b-4144-4&from=paste&height=164&id=uab4fd245&originHeight=328&originWidth=2350&originalType=binary&ratio=2&rotation=0&showTitle=false&size=259703&status=done&style=none&taskId=u4aa5d723-f988-41e6-86fc-8c08d59e517&title=&width=1175" />
<h2 id="痛点-2长尾应用资源成本高">痛点 2：长尾应用资源成本高</h2>
<p>在企业中，80% 的应用只服务了不到 20% 的流量，同时伴随着业务的变化，企业存在大量的<strong>长尾应用</strong>，这些长尾应用 CPU 使用率长期不到 10%，造成了极大的<strong>资源浪费</strong>。<br />通过使用 <strong>SOFAServerless</strong> <strong>合并部署</strong>与配套工具，您可以低成本的实现多个应用的合并部署，从而解决企业应用过度拆分和低流量业务带来的<strong>资源浪费</strong>，<strong>节约成本</strong>。<br />
<img width="700px" src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/671/1694593117757-d2932c29-c4c2-4ecc-9a41-59a750d53823.png#clientId=u0d56718b-4144-4&from=paste&height=132&id=u349c574f&originHeight=318&originWidth=1382&originalType=binary&ratio=2&rotation=0&showTitle=false&size=158864&status=done&style=none&taskId=u1389af9d-06db-468f-810a-09bc615b751&title=&width=574" /><br />
这里 “业务A 应用1” 在 SOFAServerless 术语中叫 “模块”。多个模块应用可以使用 SOFAArk 技术合并到同一个基座。基座可以是完全空的 SpringBoot应用（Java 技术栈），也可以下沉一些公共 SDK 到基座，模块应用每次发布会重启基座机器。在这种方式下，模块应用最大程度复用了基座的<strong>内存</strong>（Metaspace 和 Heap），构建产物<strong>大小</strong>也能从<strong>数百 MB</strong> 瘦身到<strong>几十 MB</strong> 甚至更激进，<strong>CPU 使用率</strong>也得到了有效提升。</p>
<h2 id="痛点-3企业研发协作效率低">痛点 3：企业研发协作效率低</h2>
<p>在企业中，一些应用需要<strong>多人开发</strong>协作。在传统研发模式下，每一个人的代码变更都需要发布整个应用，这就导致应用需要以<strong>赶火车</strong>式的方式进行研发迭代，大家需要统一一个时间窗口做迭代开发，统一的时间点做发布上线，因此存在大量的需求上线相互<strong>等待</strong>、环境机器<strong>抢占</strong>、迭代<strong>冲突</strong>等情况。<br />通过使用 <strong>SOFAServerless</strong>，您可以方便的将应用拆分为一个<strong>基座</strong>与多个功能<strong>模块</strong>，一个功能模块就是一组代码文件。不同的功能模块可以<strong>同时进行</strong>迭代开发和发布运维，模块间<strong>互不感知互不影响</strong>，这样就消除了传统应用迭代赶火车式的相互等待，每个模块拥有自己的独立迭代，<strong>需求交付效率</strong>因此得到了极大提升。如果您对模块额外启用了<strong>热部署</strong>方式（也可以每次发布模块重启整个基座），那么模块的单次构建+发布也会从普通应用的 <strong>6 - 10 分钟减少到十秒级。</strong><br />
<img width="800px" src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/671/1694594675815-3037ffe1-2048-4c86-bc50-456697b197d5.png#clientId=u0d56718b-4144-4&from=paste&height=552&id=u36ac4b83&originHeight=1066&originWidth=1154&originalType=binary&ratio=2&rotation=0&showTitle=false&size=428189&status=done&style=none&taskId=u7fc53ae9-ff48-4ae5-a821-44dbee64aaa&title=&width=598" /></p>
<h2 id="痛点-4难以沉淀业务资产提高中台效率">痛点 4：难以沉淀业务资产提高中台效率</h2>
<p>在一些中大型企业中，会沉淀各种<strong>业务中台</strong>应用。中台一般封装了业务的公共 API 实现，和 <strong>SPI</strong> 定义。其中 SPI 定义允许中台上的插件去实现各自的业务逻辑，流量进入中台应用后，会调用对应的 SPI 实现组件去完成相应的业务逻辑。中台应用内的组件，业务逻辑一般不复杂，如果拆出去部署为独立应用会带来高昂的<strong>资源成本和运维成本</strong>，而且构建发布<strong>速度很慢</strong>，严重加剧研发负担影响研发效率。<br />通过使用 SOFAServerless，您可以方便的将中台应用拆分一个<strong>基座</strong>和多个功能<strong>模块</strong>。基座可以沉淀比较厚的业务依赖、公共逻辑、API 实现、SPI 定义等（即所谓的业务资产），提供给上面的模块使用。模块使用基座的能力可以是对象之间或 Bean 之间的<strong>直接调用</strong>，代码几乎不用改造。而且多个模块间可以<strong>同时进行</strong>迭代开发和发布运维，<strong>互不感知互不影响</strong>，<strong>协作交付效率</strong>得到了极大提升。此外对于比较简单的模块还可以开启热部署，单次构建+发布也会从普通应用的 <strong>6 - 10 分钟减少到 30 秒内。</strong><br />
<img width="800px" src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/671/1694601773808-b25f5beb-a4e4-4d93-ba55-6f61bf0377bc.png#clientId=u2162a7aa-3111-4&from=paste&height=386&id=uf98e4ae9&originHeight=1016&originWidth=1400&originalType=binary&ratio=2&rotation=0&showTitle=false&size=470581&status=done&style=none&taskId=u44970d8c-1234-447f-bbb6-ceea4a44cfc&title=&width=532" /></p>
<h2 id="痛点-5微服务演进成本高">痛点 5：微服务演进成本高</h2>
<p>企业里不同业务有不同的发展阶段，因此应用也拥有自己的生命周期。</p>
<p><strong>初创期</strong>：一个初创的应用一般会先采用<strong>单体架构</strong>。<br />↓<br /><strong>增长期</strong>：随着业务增长，应用开发者也随之增加。此时您可能<strong>不确定</strong>业务的未来前景，也不希望过早把业务拆分成多个应用以避免不必要的<strong>维护、治理和资源成本</strong>，那么您可以用 <strong>SOFAServerless</strong> 低成本地将应用<strong>拆分</strong>为一个基座和多个功能<strong>模块</strong>，不同功能模块之间可以并行研发运维独立迭代，从而提高应用在此阶段的研发协作和<strong>需求交付</strong>效率。<br />↓<br /><strong>成熟期</strong>：随着业务进一步增长，您可以使用 SOFAServerless 低成本地将部分或全部功能模块<strong>拆分成独立应用</strong>去研发运维。<br />↓<br /><strong>长尾期</strong>：部分业务在经历增长期或者成熟期后，也可能慢慢步入到低活状态或者长尾状态，此时您可以用 SOFAServerless 低成本地将这些应用<strong>一键改回模块</strong>，<strong>合并部署</strong>到一起实现<strong>降本增效</strong>。</p>
<p>可以看到 <strong>SOFAServerless</strong> 支持企业应用低成本地在初创期、增长期、成熟期、长尾期之间平滑过渡甚至来回切换，从而轻松让应用架构与业务发展保持同步。<br />应用生命周期演进<br />
<img width="1200px" src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/671/1694602307402-510d44ec-314c-44c4-96d8-bb978dd027ff.png#clientId=u2162a7aa-3111-4&from=paste&height=217&id=u8b5b547c&originHeight=434&originWidth=2458&originalType=binary&ratio=2&rotation=0&showTitle=false&size=266126&status=done&style=none&taskId=u09776530-0a41-4081-be17-c42db50e8b1&title=&width=1229" /></p>
<br/>
<br/>

</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-3a89b12892834b585df4690bf050d9d5">1.2 - 行业背景</h1>
    
	<h2 id="微服务的问题">微服务的问题</h2>
<p>应用架构从单体应用发展到微服务，结合软件工程从瀑布模式到当前的 DevOps 模式的发展，解决了可扩展、分布式、分工协作等问题，为企业提供较好的敏捷性与执行效率，带来了明显的价值。但该模式发展至今，虽然解决了一些问题，也有微服务的一些问题慢慢暴露出来，在当前已经得到持续关注：</p>
<h3 id="基础设施复杂">基础设施复杂</h3>
<h4 id="认知负载高">认知负载高</h4>
<p><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1695086284703-13a90661-9735-4daa-a7ec-dfc3a28ca2bd.png#clientId=ue95e757a-3cd6-4&amp;from=paste&amp;height=260&amp;id=ubf4cf860&amp;originHeight=942&amp;originWidth=1738&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=404365&amp;status=done&amp;style=none&amp;taskId=udcdc41a4-9949-4f53-98ca-e722e63bfc8&amp;title=&amp;width=479" alt="image.png"><br />当前业务要完成一个需求，背后实际上有非常多的依赖、组件和平台在提供各种各样的能力，只要这些业务以下的某一个组件出现异常被业务感知到，都会对业务研发人员带来较大认知负担和对应恢复的时间成本。<br /><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1695086591548-8ac5f4b6-b5e2-4ba4-aa1e-35ff6816634a.png#clientId=ue95e757a-3cd6-4&amp;from=paste&amp;height=200&amp;id=ub7a3e5b4&amp;originHeight=596&amp;originWidth=582&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=415294&amp;status=done&amp;style=none&amp;taskId=u6e187ff5-dade-4172-83e4-38a90d4ad38&amp;title=&amp;width=195" alt="image.png"><br />异常种类繁多</p>
<h4 id="运维负担重">运维负担重</h4>
<p>业务包含的各个依赖也会不断迭代升级，例如框架、中间件、各种 sdk 等，在遇到</p>
<ol>
<li>重要功能版本发布</li>
<li>修复紧急 bug</li>
<li>遇到重大安全漏洞</li>
</ol>
<p>等情况时，这些依赖的新版本就需要业务尽可能快的完成升级，这造成了两方面的问题：</p>
<h5 id="对于业务研发人员">对于业务研发人员</h5>
<p>这些依赖的升级如果只是一次两次那么就不算是问题，但是一个业务应用背后依赖的框架、中间件与各类 sdk 是很多的，每一个依赖发布这些升级都需要业务同学来操作，这么多个依赖的话长期上就会对业务研发同学来说是不小的运维负担。另外这里也需要注意到业务公共层对业务开发者来说也是不小的负担。</p>
<h5 id="对于基础设施人员">对于基础设施人员</h5>
<p>类似的对于各个依赖的开发人员自身，每发布一个这样的新版本，需要尽可能快的让使用的业务应用完成升级。但是业务研发人员更关注业务需求交付，想要推动业务研发人员快速完成升级是不太现实的，特别是在研发人员较多的企业里。</p>
<h4 id="启动慢">启动慢</h4>
<p>每个业务应用启动过程都需要涉及较多过程，造成一个功能验证需要花费较长等待时间。<br /><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1695088271232-52d649a0-0e21-46b3-aaf4-43d0d908d279.png#clientId=ue95e757a-3cd6-4&amp;from=paste&amp;height=83&amp;id=uf009ae3a&amp;originHeight=180&amp;originWidth=1234&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=52685&amp;status=done&amp;style=none&amp;taskId=u56e65597-48ba-47f8-b8b6-c69a8ceebf3&amp;title=&amp;width=570" alt="image.png"></p>
<h4 id="发布效率低">发布效率低</h4>
<p>由于上面提到的启动慢、异常多的问题，在发布上线过程中需要较长时间，出现异常导致卡单需要恢复处理。发布过程中除了平台异常外，机器异常发生的概率会随着机器数量的增多而增多，假如一台机器正常完成发布（不发生异常）的概率是 99.9%，也就是一次性成功率为 99.9%，那么100台则是 90%，1000台则降低到了只有 36.7%，所以对于机器较多的应用发布上线会经常遇到卡单的问题，这些都需要研发人员介入处理，导致效率低。</p>
<h3 id="协作与资源成本高">协作与资源成本高</h3>
<h4 id="单体应用大应用过大">单体应用/大应用过大</h4>
<p><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1695109775918-de436da0-8187-45a8-a30a-62177a55181e.png#clientId=u02591eed-2e18-4&amp;from=paste&amp;height=106&amp;id=u28baf164&amp;originHeight=304&amp;originWidth=1412&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=97660&amp;status=done&amp;style=none&amp;taskId=u468dfc48-8b76-484e-abb6-36aed56dfd8&amp;title=&amp;width=494" alt="image.png"></p>
<h5 id="多人协作阻塞">多人协作阻塞</h5>
<p>业务不断发展，应用会不断变大，这主要体现在开发人员不断增多，出现多人协作阻塞问题。</p>
<h5 id="变更影响面大风险高">变更影响面大，风险高</h5>
<p>业务不断发展，线上流量不断增大，机器数量也不断增多，但当前一个变更可能影响全部代码和机器流量，变更影响面大风险高。</p>
<h4 id="小应用过多">小应用过多</h4>
<p><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1695111071288-b27e64a3-ff6f-4457-9353-5a4b337faccf.png#clientId=u02591eed-2e18-4&amp;from=paste&amp;height=110&amp;id=ua230cdfe&amp;originHeight=302&amp;originWidth=1404&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=76471&amp;status=done&amp;style=none&amp;taskId=ua211c1f6-fe53-43fa-8be8-7da9a92e8cb&amp;title=&amp;width=512" alt="image.png"><br />在微服务发展过程中，随着时间的推移，例如部分应用拆分过多、某些业务萎缩、组织架构调整等，都会出现线上小应用或者长尾应用不断积累，数量越来越多，像蚂蚁过去3年应用数量增长了 3倍。<br /><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1695111122234-8a85eee7-bdf5-40c6-85e2-5955413f9c7d.png#clientId=u02591eed-2e18-4&amp;from=paste&amp;height=177&amp;id=uf7c75dd0&amp;originHeight=1182&amp;originWidth=1538&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=140920&amp;status=done&amp;style=none&amp;taskId=uaadf29d5-7052-4316-9073-5ce5a4f92d4&amp;title=&amp;width=230" alt="image.png"></p>
<h5 id="资源成本高">资源成本高</h5>
<p>这些应用每个机房都需要几台机器，但其实流量也不大，cpu 使用率很低，造成资源浪费。</p>
<h5 id="长期维护成本">长期维护成本</h5>
<p>这些应用同样需要人员来维度，例如升级 SDK，修复安全漏洞等，长期维护成本高。</p>
<h4 id="问题必然性">问题必然性</h4>
<p>微服务系统是个生态，在一个公司内发展演进几年后，参考28定律，少数的大应用占有大量的流量，不可避免的会出现大应用过大和小应用过多的问题。<br />然而大应用多大算大，小应用多少算多，这没有定义的标准，所以这类问题造成的研发人员的痛点是隐匿的，没有痛到一定程度是较难引起公司管理层面的关注和行动。</p>
<h3 id="如何合理拆分微服务">如何合理拆分微服务</h3>
<p>微服务如何合理拆分始终是个老大难的问题，合理拆分始终没有清晰的标准，这也是为何会存在上述的大应用过大、小应用过多问题的原因。而这些问题背后的根因是业务与组织灵活，与微服务拆分的成本高，两者的敏捷度不一致。</p>
<h4 id="微服务的拆分与业务和组织发展敏捷度不一致">微服务的拆分与业务和组织发展敏捷度不一致</h4>
<p><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1695113016136-8d591312-1300-496e-9df8-a5ed1a49abe4.png#clientId=u02591eed-2e18-4&amp;from=paste&amp;height=201&amp;id=u7ce79cce&amp;originHeight=554&amp;originWidth=1222&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=182342&amp;status=done&amp;style=none&amp;taskId=uf3c867d4-2d82-4922-a6d9-6572ca3a1f7&amp;title=&amp;width=443" alt="image.png"><br />业务发展灵活，组织架构也在不断调整，而微服务拆分需要机器与长期维护的成本，两者的敏捷度不一致，导致容易出现未拆或过度拆分问题，从而出现大应用过大和小应用过多问题。这类问题不从根本上解决，会导致微服务应用治理过一波之后还会再次出现问题，导致研发同学始终处于低效的痛苦与治理的痛苦循环中。</p>
<h3 id="不同体量企业面对的问题">不同体量企业面对的问题</h3>
<p><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1695131026232-1e25044b-d0d4-4a58-9d03-ef665365fbc6.png#clientId=ucec7e736-7c4f-4&amp;from=paste&amp;height=511&amp;id=uc85ea670&amp;originHeight=1022&amp;originWidth=3766&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=244352&amp;status=done&amp;style=none&amp;taskId=u18416169-fc43-47a4-8486-9e5e328552c&amp;title=&amp;width=1883" alt="image.png"></p>
<h3 id="行业尝试的解法">行业尝试的解法</h3>
<p>当前行业里也有很多不错的思路和项目在尝试解决这些问题，例如服务网格、应用运行时、平台工程，Spring Modulith、Google ServiceWeaver，有一定的效果，但也存在一定的局限性：</p>
<ol>
<li>从业务研发人员角度看，只屏蔽部分基础设施，未屏蔽业务公共部分</li>
<li>只解决其中部分问题</li>
<li>存量应用接入改造成本高</li>
</ol>
<p>SOFAServerless 的目的是为了解决这些问题而不断演进出来的一套研发框架与平台能力。</p>
<br/>
<br/>

</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-1a655298f9f51d3790e457c666fd9032">1.3 - 架构介绍</h1>
    
	
</div>



    
      
  
  
  
  

  
  

  
    
    
	
    

<div class="td-content" style="">
    
	<h1 id="pg-eae697a827c518b3c38ed9ee18d3ff71">1.3.1 - 架构原理</h1>
    
	<h2 id="模块化应用架构">模块化应用架构</h2>
<p>为了解决这些问题，我们对应用同时做了横向和纵向的拆分。首先第一步纵向拆分：把应用拆分成<strong>基座</strong>和<strong>业务</strong>两层，这两层分别对应两层的组织分工。基座小组与传统应用一样，负责机器维护、通用逻辑沉淀、业务架构治理，并为业务提供运行资源和环境。通过关注点分离的方式为业务屏蔽业务以下所有基础设施，聚焦在业务自身上。第二部我们将业务进行横向切分出多个模块，多个模块之间独立并行迭代互不影响，同时模块由于不包含基座部分，构建产物非常轻量，启动逻辑也只包含业务本身，所以启动快，具备秒级的验证能力，让模块开发得到极致的提效。<br /><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1695131313965-18385213-eded-4a6b-b554-db5312fa2c9d.png#clientId=ua84a92a5-30aa-4&amp;from=paste&amp;height=431&amp;id=udb6b29d5&amp;originHeight=862&amp;originWidth=3448&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=192627&amp;status=done&amp;style=none&amp;taskId=u9a114a24-0887-48d9-87b2-57d3e15eb80&amp;title=&amp;width=1724" alt="image.png"><br />拆分之前，每个开发者可能感知从框架到中间件到业务公共部分到业务自身所有代码和逻辑，拆分后，团队的协作分工也从发生改变，研发人员分工出两种角色，基座和模块开发者，模块开发者不关系资源与容量，享受秒级部署验证能力，聚焦在业务逻辑自身上。<br /><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1695131554610-ef5c4a2f-0080-45eb-8fed-55fdf5d827f9.png#clientId=ua84a92a5-30aa-4&amp;from=paste&amp;height=459&amp;id=u7227f759&amp;originHeight=918&amp;originWidth=3714&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=309179&amp;status=done&amp;style=none&amp;taskId=u12307968-2a79-4f77-9c78-e976399c60e&amp;title=&amp;width=1857" alt="image.png"></p>
<p>这里要重点看下我们是如何做这些纵向和横向切分的，切分是为了隔离，隔离是为了能够独立迭代、剥离不必要的依赖，然而如果只是隔离是没有共享相当于只是换了个部署的位置而已，很难有好的效果。所以我们除了隔离还有共享能力，所以这里需要聚焦在隔离与共享上来理解模块化架构背后的原理。</p>
<h3 id="模块的定义">模块的定义</h3>
<p>在这之前先看下这里的模块是什么？模块是通过原来应用减去基座部分得到的，这里的减法是通过设置模块里依赖的 scope 为 provided 实现的，<br /><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1695132446404-0571be28-5cdf-452e-90f5-001a4209c750.png#clientId=u177778f7-e9cd-4&amp;from=paste&amp;height=142&amp;id=ud796498d&amp;originHeight=516&amp;originWidth=1834&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=108247&amp;status=done&amp;style=none&amp;taskId=u8201db6e-cf5e-4fbd-ab24-6a0223e1709&amp;title=&amp;width=506" alt="image.png"><br /><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1695132481921-6fb1c3da-0de3-46ce-bf8e-cc645f63157c.png#clientId=u177778f7-e9cd-4&amp;from=paste&amp;height=187&amp;id=u31cba15e&amp;originHeight=524&amp;originWidth=1026&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=205261&amp;status=done&amp;style=none&amp;taskId=u2c981d7a-dfff-43c6-b6c6-5c6a5701d2b&amp;title=&amp;width=367" alt="image.png"><br />一个模块可以由这三点定义：</p>
<ol>
<li>SpringBoot 打包生成的 jar 包</li>
<li>一个模块： 一个 SpringContext + 一个 ClassLoader</li>
<li>热部署（升级的时候不需要启动进程）</li>
</ol>
<h3 id="模块的隔离与共享">模块的隔离与共享</h3>
<p>模块通过 ClassLoader 隔离配置和代码，SpringContext 隔离 Bean 和服务，可以通过调用 Spring ApplicationContext 的start close 方法来动态启动和关闭服务。通过 SOFAArk 来共享模块和基座的配置和代码 Class，通过 SpringContext Manager 来共享多模块间的 Bean 和服务。<br /><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1695132610081-3efe470f-5c65-4d46-b4e4-1ecb15c8d789.png#clientId=u771aab18-101c-4&amp;from=paste&amp;height=313&amp;id=u4c63a679&amp;originHeight=972&amp;originWidth=1334&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=160772&amp;status=done&amp;style=none&amp;taskId=uafe9a1eb-025c-4e1e-9316-35b8bd32b96&amp;title=&amp;width=429" alt="image.png"><br />并且在 JVM 内通过</p>
<ol>
<li>Ark Container 提供多 ClassLoader 运行环境</li>
<li>Arklet 来管理模块生命周期</li>
<li>Framework Adapter 将 SpringBoot 生命周期与模块生命周期关联起来</li>
<li>SOFAArk 默认委托加载机制，打通模块与基座类委托加载</li>
<li>SpringContext Manager 提供 Bean 与服务发现调用机制</li>
<li>基座本质也是模块，拥有独立的 SpringContext 和 ClassLoader</li>
</ol>
<p><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1695139080634-1669ea76-c486-47fc-ac4f-5900833896b9.png#clientId=u71a0730f-fb54-4&amp;from=paste&amp;height=275&amp;id=u1cf30803&amp;originHeight=722&amp;originWidth=1428&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=198221&amp;status=done&amp;style=none&amp;taskId=u88cd7c27-4850-4b02-9c6f-504b4456a94&amp;title=&amp;width=544" alt="image.png"></p>
<p>但是在 Java 领域模块化技术已经发展了20年了，为什么这里的模块化技术能够在蚂蚁内部规模化落地，这里的核心原因是<br /><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1695139240123-37a5b5e7-38ee-4b33-b84b-4d58e8b9f371.png#clientId=u71a0730f-fb54-4&amp;from=paste&amp;height=596&amp;id=u7b5e0183&amp;originHeight=1192&amp;originWidth=2954&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=587199&amp;status=done&amp;style=none&amp;taskId=uc2ceea08-092e-4bfd-9566-d97ab3d3b74&amp;title=&amp;width=1477" alt="image.png"><br />基于 SOFAArk 和 SpringContext Manager 的多模块能力，提供了低成本的使用方式。</p>
<h4 id="隔离方面">隔离方面</h4>
<p>对于其他的模块化技术，从隔离角度来看，JPMS 和 Spring Modulith 的隔离是通过自定义的规则来做限制的，Spring Modulith 还需要在单元测试里执行 verify 来做校验，隔离能力比较弱且一定程度上是比较 tricky 的，对于存量应用使用来说也是有不小改造成本的，甚至说是存量应用无法改造。而 SOFAArk 和 OSGI 一样采用 ClassLoader 和 SpringContext 的方式进行配置与代码、bean与服务的隔离，对原生应用的启动模式完全保持一致。</p>
<h4 id="共享方面">共享方面</h4>
<p>SOFAArk 的隔离方式和 OSGI 是一致的，但是在共享方面 OSGI 和 JPMS、Spring Modulith 一样都需要在源模块和目标模块间定义导入导出列表或其他配置，这造成业务使用模块需要强感知和理解多模块的技术，使用成本是比较高的，而 SOFAArk 则定义了默认的类委托加载机制，和跨模块的 Bean 和服务发现机制，让业务不用改造的情况下能够使用多模块的能力。<br />这里额外提下，为什么基于 SOFAArk 的多模块化技术能提供这些默认的能力，而做到低成本的使用呢？这里主要的原因是因为我们对模块做了角色的区分，区分出了基座与模块，在这个核心原因基础上也对低成本使用这块比较重视，做了重要的设计考量和取舍。具体有哪些设计和取舍，可以查看技术实现文章。</p>
<h3 id="模块间通信">模块间通信</h3>
<p>模块间通信主要依托 SpringContext Manager 的 Bean 与服务发现调用机制提供基础能力，<br /><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1695171905613-2546f555-ff25-4a58-81aa-02d77bfb2b1d.png#clientId=ud7a2066a-ba29-4&amp;from=paste&amp;height=307&amp;id=uc8826222&amp;originHeight=724&amp;originWidth=1048&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=202275&amp;status=done&amp;style=none&amp;taskId=u537670c5-c728-487a-9710-80986ce8532&amp;title=&amp;width=444" alt="image.png"></p>
<h3 id="模块的可演进">模块的可演进</h3>
<p>回顾背景里提到的几大问题，可以看到通过模块化架构的隔离与共享能力，可以解决掉基础设施复杂、多人协作阻塞、资源与长期维护成本高的问题，但还有微服务拆分与业务敏捷度不一致的问题未解决。<br /><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1695175219841-965cd163-a4bd-4cd0-b828-c620b29c0ffc.png#clientId=uaaa65411-0843-4&amp;from=paste&amp;height=185&amp;id=ua68375b7&amp;originHeight=894&amp;originWidth=2906&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=417377&amp;status=done&amp;style=none&amp;taskId=ud94c9602-7cd1-4bcb-8654-39fe8938d37&amp;title=&amp;width=602" alt="image.png"><br />在这里我们通过降低微服务拆分的成本来解决，那么怎么降低微服务拆分成本呢？这里主要是在单体架构和微服务架构之间增加模块化架构</p>
<ol>
<li>模块不占资源所以拆分没有资源成本</li>
<li>模块不包含业务公共部分和框架、中间件部分，所以模块没有长期的 sdk 升级维护成本</li>
<li>模块自身也是 SpringBoot，我们提供工具辅助单体应用低成本拆分成模块应用</li>
<li>模块具备灵活部署能力，可以合并部署在一个 JVM 内，也可拆除独立部署，这样模块可以按需低成本演进成微服务或回退会单体应用模式</li>
</ol>
<p><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1695175141130-d3b55e17-70c3-4e7c-aeef-2e071f89ada8.png#clientId=uaaa65411-0843-4&amp;from=paste&amp;height=316&amp;id=u589ef06e&amp;originHeight=632&amp;originWidth=3642&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=139102&amp;status=done&amp;style=none&amp;taskId=uf9f96d68-7456-4af5-951e-d9351092988&amp;title=&amp;width=1821" alt="image.png"><br />图中的箭头是双向的，如果当前微服务拆分过多，也可以将多个微服务低成本改造成模块合并部署在一个 JVM 内。所以这里的本质是通过在单体架构和微服务架构之间增加一个可以双向过渡的模块化架构，降低改造成本的同时，也让开发者可以根据业务发展按需演进或回退。这样可以把微服务的这几个问题解决掉</p>
<h3 id="模块化架构的优势">模块化架构的优势</h3>
<p>模块化架构的优势主要集中在这四点：快、省、灵活部署、可演进，<br /><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1695180240688-82520d0c-2304-47dc-a9f3-22af08424100.png#clientId=ueb39d37f-ca7b-4&amp;from=paste&amp;height=237&amp;id=u4c60feb3&amp;originHeight=688&amp;originWidth=1504&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=437668&amp;status=done&amp;style=none&amp;taskId=uf04ead3d-7cf7-41e7-bfff-81857bf5918&amp;title=&amp;width=518" alt="image.png"></p>
<p>与传统应用对比数据如下，可以看到在研发阶段、部署阶段、运行阶段都得到了10倍以上的提升效果。<br /><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1695180250909-f5eca1b3-c416-4bac-9732-549a9bed8b87.png#clientId=ueb39d37f-ca7b-4&amp;from=paste&amp;height=261&amp;id=u8907b613&amp;originHeight=522&amp;originWidth=2838&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=219589&amp;status=done&amp;style=none&amp;taskId=ua4b2bd1b-a75f-4945-abce-68826a43377&amp;title=&amp;width=1419" alt="image.png"></p>
<h2 id="平台架构">平台架构</h2>
<p>只有应用架构还不够，需要从研发阶段到运维阶段到运行阶段都提供完整的配套能力，才能让模块化应用架构的优势真正触达到研发人员。<br /><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1695182073971-12b14861-b6fa-470c-a140-737d40ff0b3e.png#clientId=u9014394b-3a6a-4&amp;from=paste&amp;height=192&amp;id=ub53430b2&amp;originHeight=384&amp;originWidth=1720&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=79335&amp;status=done&amp;style=none&amp;taskId=u1eb2a897-c2ca-437f-8d56-7067be175e2&amp;title=&amp;width=860" alt="image.png"><br />在研发阶段，需要提供基座接入能力，模块创建能力，更重要的是模块的本地快速构建与联调能力；在运维阶段，提供快速的模块发布能力，在模块发布基础上提供 A/B 测试和秒级扩缩容能力；在运行阶段，提供模块的可靠性能力，模块可观测、流量精细化控制、调度和伸缩能力。</p>
<p><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1695182125970-f9529014-0386-4922-b8eb-5d0c82a7e5d8.png#clientId=u9014394b-3a6a-4&amp;from=paste&amp;height=370&amp;id=uf365ffd8&amp;originHeight=740&amp;originWidth=2096&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=242246&amp;status=done&amp;style=none&amp;taskId=uf07de18d-931e-4ffd-9540-d4be10de3e7&amp;title=&amp;width=1048" alt="image.png"><br />组件视图</p>
<p>在整个平台里，需要四个组件：</p>
<ol>
<li>研发工具 Arkctl, 提供模块创建、快速联调测试等能力</li>
<li>运行组件 SOFAArk, Arklet，提供模块运维、模块生命周期管理，多模块运行环境</li>
<li>控制面组件 ModuleController
<ol>
<li>ModuleDeployment 提供模块发布与运维能力</li>
<li>ModuleScheduler 提供模块调度能力</li>
<li>ModuleScaler 提供模块伸缩能力</li>
</ol>
</li>
</ol>
<br/>

</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-f3857e8be17ade9a35d641cc483d619b">1.3.2 - 基座与模块间类委托加载原理介绍</h1>
    
	<h2 id="多模块间类委托加载">多模块间类委托加载</h2>
<p>SOFAArk 框架是基于多 ClassLoader 的通用类隔离方案，提供类隔离和应用的合并部署能力。本文档并不打算介绍 SOFAArk 类隔离的<a href="https://www.sofastack.tech/projects/sofa-boot/sofa-ark-classloader/">原理与机制</a>，这里主要介绍多 ClassLoader 当前的最佳实践。<br />当前基座与模块部署在 JVM 上的 ClassLoader 模型如图：<br /><img src="https://intranetproxy.alipay.com/skylark/lark/0/2022/png/149473/1653304883689-ec30b72b-1620-4a2a-8611-d6c24107afd2.png#clientId=u8aaeb3a3-ec6f-4&amp;from=paste&amp;height=225&amp;id=u1df6aa1c&amp;originHeight=450&amp;originWidth=388&amp;originalType=binary&amp;ratio=1&amp;rotation=0&amp;showTitle=false&amp;size=39808&amp;status=done&amp;style=none&amp;taskId=uf6233ec3-9494-4b6a-b1b6-43546035a43&amp;title=&amp;width=194" alt="image.png"></p>
<h2 id="当前类委托加载机制">当前类委托加载机制</h2>
<p>当前一个模块在启动与运行时查找的类，有两个来源：当前模块本身，基座。这两个来源的理想优先级顺序是，优先从模块中查找，如果模块找不到再从基座中查找，但当前存在一些特例：</p>
<ol>
<li>当前定义了一份白名单，白名单范围内的依赖会强制使用基座里的依赖。</li>
<li>模块可以扫描到基座里的所有类：
<ul>
<li>优势：模块可以引入较少依赖</li>
<li>劣势：模块会扫描到模块代码里不存在的类，例如会扫描到一些 AutoConfiguration，初始化时由于第四点扫描不到对应资源，所以会报错。</li>
</ul>
</li>
<li>模块不能扫描到基座里的任何资源：
<ul>
<li>优势：不会与基座重复初始化相同的 Bean</li>
<li>劣势：模块启动如果需要基座的资源，会因为查找不到资源而报错，除非模块里显示引入（Maven 依赖 scope 不设置成 provided）</li>
</ul>
</li>
<li>模块调用基座时，部分内部处理传入模块里的类名到基座，基座如果存在直接从基座 ClassLoader 查找模块传入的类，会查找不到。因为委托只允许模块委托给基座，从基座发起的类查找不会再次查找模块里的。</li>
</ol>
<h3 id="使用时需要注意事项">使用时需要注意事项</h3>
<p>模块要升级委托给基座的依赖时，需要让基座先升级，升级之后模块再升级。</p>
<h2 id="类委托的最佳实践">类委托的最佳实践</h2>
<p>类委托加载的准则是中间件相关的依赖需要放在同一个的 ClassLoader 里进行加载执行，达到这种方式的最佳实践有两种：</p>
<h3 id="强制委托加载">强制委托加载</h3>
<p>由于中间件相关的依赖一般需要在同一个 ClassLoader 里加载运行，所以我们会制定一个中间件依赖的白名单，强制这些依赖委托给基座加载。</p>
<h4 id="使用方法">使用方法</h4>
<p>application.properties 里增加配置 <code>sofa.ark.plugin.export.class.enable=true</code>。</p>
<h4 id="优点">优点</h4>
<p>模块开发者不需要感知哪些依赖属于需要强制加载由同一个 ClassLoader 加载的依赖。</p>
<h4 id="缺点">缺点</h4>
<p>白名单里要强制加载的依赖列表需要维护，列表的缺失需要更新基座，较为重要的升级需要推所有的基座升级。</p>
<h3 id="自定义委托加载">自定义委托加载</h3>
<p>模块里 pom 通过设置依赖的 scope 为 <code>provided</code>主动指定哪些要委托给基座加载。通过模块瘦身把与基座重复的依赖委托给基座加载，并在基座里预置中间件的依赖（可选，虽然模块暂时不会用到，但可以提前引入，以备后续模块需要引入的时候不需再发布基座即可引入）。这里：</p>
<ol>
<li>基座尽可能的沉淀通用的逻辑和依赖，特别是中间件相关以 <code>xxx-alipay-sofa-boot-starter </code>命名的依赖。</li>
<li>基座里预置一些公共依赖（可选）。</li>
<li>模块里的依赖如果基座里面已经有定义，则模块里的依赖尽可能的委托给基座，这样模块会更轻（提供自动模块瘦身的工具）。模块里有两种途径设置为委托给基座：
<ol>
<li>依赖里的 scope 设置为 provided，注意通过 mvn dependency:tree 查看是否还有其他依赖设置成了 compile，需要所有的依赖引用的地方都设置为 provided。</li>
<li>biz 打包插件<code>sofa-ark-maven-plugin</code>里设置 <code>excludeGroupIds</code> 或 <code>excludeArtifactIds</code></li>
</ol>
</li>
</ol>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-xml" data-lang="xml"><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&lt;plugin&gt;</span>
</span></span><span style="display:flex;"><span>                <span style="color:#204a87;font-weight:bold">&lt;groupId&gt;</span>com.alipay.sofa<span style="color:#204a87;font-weight:bold">&lt;/groupId&gt;</span>
</span></span><span style="display:flex;"><span>                <span style="color:#204a87;font-weight:bold">&lt;artifactId&gt;</span>sofa-ark-maven-plugin<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
</span></span><span style="display:flex;"><span>                <span style="color:#204a87;font-weight:bold">&lt;configuration&gt;</span> 
</span></span><span style="display:flex;"><span>                    <span style="color:#204a87;font-weight:bold">&lt;excludeGroupIds&gt;</span>io.netty,org.apache.commons,......<span style="color:#204a87;font-weight:bold">&lt;/excludeGroupIds&gt;</span>
</span></span><span style="display:flex;"><span>                    <span style="color:#204a87;font-weight:bold">&lt;excludeArtifactIds&gt;</span>validation-api,fastjson,hessian,slf4j-api,junit,velocity,......<span style="color:#204a87;font-weight:bold">&lt;/excludeArtifactIds&gt;</span>
</span></span><span style="display:flex;"><span>                    <span style="color:#204a87;font-weight:bold">&lt;declaredMode&gt;</span>true<span style="color:#204a87;font-weight:bold">&lt;/declaredMode&gt;</span>
</span></span><span style="display:flex;"><span>                <span style="color:#204a87;font-weight:bold">&lt;/configuration&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&lt;/plugin&gt;</span>
</span></span></code></pre></div><p>通过 2.a 的方法需要确保所有声明的地方 scope 都设置为provided，通过2.b的方法只要指定一次即可，建议使用方法 2.b。</p>
<ol start="4">
<li>只有模块声明过的依赖才可以委托给基座加载。</li>
</ol>
<p>模块启动的时候，Spring 框架会有一些扫描逻辑，这些扫描如果不做限制会查找到模块和基座的所有资源，导致一些模块明明不需要的功能尝试去初始化，从而报错。SOFAArk 2.0.3 之后新增了模块的 declaredMode, 来限制只有模块里声明过的依赖才可以委托给基座加载。只需在模块的打包插件的 Configurations 里增加  <code>&lt;declaredMode&gt;true&lt;/declaredMode&gt;</code>即可。</p>
<h4 id="优点-1">优点</h4>
<p>不需要维护 plugin 的强制加载列表，当部分需要由同一 ClassLoader 加载的依赖没有设置为统一加载时，可以修改模块就可以修复，不需要发布基座（除非基座确实依赖）。</p>
<h4 id="缺点-1">缺点</h4>
<p>对模块瘦身的依赖较强。</p>
<h3 id="对比与总结">对比与总结</h3>
<table>
<thead>
<tr>
<th></th>
<th>依赖缺失排查成本</th>
<th>修复成本</th>
<th>模块改造成本</th>
<th>维护成本</th>
</tr>
</thead>
<tbody>
<tr>
<td>强制加载</td>
<td>类转换失败或类查找失败，成本中</td>
<td>更新 plugin，发布基座，高</td>
<td>低</td>
<td>高</td>
</tr>
<tr>
<td>自定义委托加载</td>
<td>类转换失败或类查找失败，成本中</td>
<td>更新模块依赖，如果基座依赖不足，需要更新基座并发布，中</td>
<td>高</td>
<td>低</td>
</tr>
<tr>
<td>自定义委托加载 + 基座预置依赖 + 模块瘦身</td>
<td>类转换失败或类查找失败，成本中</td>
<td>更新模块依赖，设置为 provided，低</td>
<td>低</td>
<td>低</td>
</tr>
</tbody>
</table>
<h4 id="结论推荐自定义委托加载方式">结论：推荐自定义委托加载方式</h4>
<ol>
<li>模块自定义委托加载 + 模块瘦身。</li>
<li>模块开启 declaredMode。</li>
<li>基座预置依赖。</li>
</ol>
<h2 id="declaredmode-开启方式">declaredMode 开启方式</h2>
<h3 id="开启条件">开启条件</h3>
<p>declaredMode 的本意是让模块能合并部署到基座上，所以开启前需要确保模块能本地启动成功。<br />如果是 SOFABoot 应用且涉及到模块调用基座服务的，本地启动因为没有基座服务，可以通过在模块 application.properties 添加这两个参数进行跳过（SpringBoot 应用无需关心）：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-properties" data-lang="properties"><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"># 如果是 SOFABoot，则：</span>
</span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"># 配置健康检查跳过 JVM 服务检查</span>
</span></span><span style="display:flex;"><span><span style="color:#c4a000">com.alipay.sofa.boot.skip-jvm-reference-health-check</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">true</span>
</span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"># 忽略未解析的占位符</span>
</span></span><span style="display:flex;"><span><span style="color:#c4a000">com.alipay.sofa.ignore.unresolvable.placeholders</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">true</span>
</span></span></code></pre></div><h3 id="开启方式">开启方式</h3>
<p>模块打包插件里增加如下配置：<br /><img src="https://intranetproxy.alipay.com/skylark/lark/0/2022/png/149473/1668428226653-d1ad571e-a580-42fa-9ca0-ff63c199dfb1.png#clientId=u664f9b10-526b-4&amp;from=paste&amp;height=399&amp;id=uf9e74e96&amp;originHeight=798&amp;originWidth=975&amp;originalType=binary&amp;ratio=1&amp;rotation=0&amp;showTitle=false&amp;size=116831&amp;status=done&amp;style=none&amp;taskId=u2287fc36-ca94-4018-94f5-5a33dcb87b2&amp;title=&amp;width=487.5" alt="image.png"></p>
<h3 id="开启后的副作用">开启后的副作用</h3>
<p>如果模块委托给基座的依赖里有发布服务，那么基座和模块会同时发布两份。</p>
<br/>

</div>



    
	
  

    
	
  

    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-6546478d87b4368b79e83eb0e32c466c">2 - 快速开始</h1>
    
	<h1 id="实验-1一键实现多应用合并部署">实验 1：一键实现多应用合并部署</h1>
<p>合并部署是指：选定一个应用作为底座，然后将多个其它应用合并部署到这个底座之上，从而实现长尾应用的极致资源降本。典型业务场景为应用的低成本交付 以及 微服务过度拆分一键重新合并。</p>
<ol>
<li>选定一个应用作为底座（SOFAServerless 术语叫<strong>基座</strong>），将普通应用<a href="/docs/tutorials/base-create/springboot-and-sofaboot/">一键升级为基座</a>。</li>
<li>选定一个应用作为上层应用（SOFAServerless 术语叫<strong>模块</strong>），将其<a href="/docs/tutorials/module-create/springboot-and-sofaboot/">一键转为模块应用并完成合并部署</a>。
<br/>
您也可以直接使用 <a href="https://github.com/sofastack/sofa-serverless/tree/master/samples/springboot-samples/service">官方 Demo 和文档</a> 在本地完成实验。</li>
</ol>
<p>小贴士：无论<strong>基座</strong>还是<strong>模块</strong>，接入 SOFAServerless 后，同一套代码分支既能像原来一样独立启动，又能做到合并部署。</p>
<br/>
<br/>
<h1 id="实验-2一键体验应用秒级热部署">实验 2：一键体验应用秒级热部署</h1>
<h2 id="步骤-1本地软件安装">步骤 1：本地软件安装</h2>
<p>下载安装 <strong>go</strong>（建议 1.20 或以上）、<strong>docker</strong>、<strong>minikube</strong>、<strong>kubectl</strong>。</p>
<h2 id="步骤-2一键启动-sofaserverless">步骤 2：一键启动 SOFAServerless</h2>
<p>使用 <strong>git</strong> 拉取 GitHub sofa-severless 项目：<a href="https://github.com/sofastack/sofa-serverless">https://github.com/sofastack/sofa-serverless</a> <br />在 <strong>module-controller</strong> 目录下执行 <strong>make dev</strong> 命令一键部署环境，会自动执行 minikube service 命令弹出网页，由于此时您还没有发布模块，所以网页不会有任何内容显示。</p>
<h2 id="步骤-3秒级发布模块">步骤 3：秒级发布模块</h2>
<p>执行以下命令：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>kubectl apply -f config/samples/module-deployment_v1alpha1_moduledeployment_provider.yaml
</span></span></code></pre></div><p>即可秒级发布上线模块应用。请等待本地 Module CR 资源 Status 字段值变更为 Available**（约 1 秒，表示模块发布完毕）**，再刷新步骤 2 自动打开的网页，即可看到一个简单的卖书页面，这个卖书逻辑就是在模块里实现的：<br /><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/671/1694161452232-15aec134-3b2a-491f-9295-0c5f8f7341af.png#clientId=ue383ca9b-aa63-4&amp;from=paste&amp;height=443&amp;id=ub3eb7eb8&amp;originHeight=1318&amp;originWidth=1626&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=168110&amp;status=done&amp;style=none&amp;taskId=u07f60163-67e4-42fa-bc41-76e43a09c1f&amp;title=&amp;width=546" alt="image.png"></p>
<h2 id="步骤-4清理本地环境">步骤 4：清理本地环境</h2>
<p>您可以使用 <strong>make undev</strong> 删除所有本地资源，清理本地环境。</p>
<br/>
<br/>
<h1 id="欢迎大家学习-sofaserverless-视频教程">欢迎大家学习 SOFAServerless 视频教程</h1>
<p><a href="/docs/tutorials/video-training">点击此处</a>查看 SOFAServerless 平台与研发框架视频培训教程。</p>

</div>



    
      
  
  
  
  

  
  

  

    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-cd27d705d8e87ceae329f27f89a34cef">3 - 视频教程</h1>
    
	<h2 id="sofaserverless-模块本地开发与上线视频教程">SOFAServerless 模块本地开发与上线视频教程</h2>
<p>小贴士: 仅需两分钟时间</p>
<video width=100% controls autoplay>
<source src="https://serverless-opensource.oss-cn-shanghai.aliyuncs.com/outer-materials/docs/videos/module_dev_and_deploy.mp4" type="video/mp4">
Your browser does not support the video tag.  
</video>
<br/>
<br/>
<p>该视频的详细文字版教程请<a href="/docs/tutorials/trial_step_by_step">点击此处</a>查看。</p>
<h2 id="sofaserverless-平台和研发框架完整视频教程">SOFAServerless 平台和研发框架完整视频教程</h2>
<p>步骤 1：<a href="https://beta.oscollege.net/product?invite=true&amp;key=1662838629963194399&amp;sign=UtWAPq5uAiBuf6uqe7LWXOTdh0a8cyvo58Ft6z9TP4O4vqyRDnfgTSjPz3cpz2JM7yC1qdgQ%2BltrZP1pNtqqB4c%2FOrSkP6GD6o0qHbI4GzErPZGTHNES2VlbiGOPzF2NRzkKE1BxLmFwfQWSF844Qb7JoNlA24t24cm6ic%2Fuv1gq4L2XYq3hxVJ7xXL1QZcG7yfJTDBGsiNdrmqBNEMpyTwNcIdPko8RoB%2B1uQbEDYUDt5xOmQnUAOuJTNxSVU3sSVTukSpLNENM7deKUaTtoLJJ%2BH4bbgrkgsufGiD1KJ7c6LSSlnkH9Vd630O6TG8s13Z%2FwFp%2FuWnxUlA2YArgjA%3D%3D">点击此处</a>注册开源学堂账号。</p>
<p>步骤 2：在开源学堂首页点击上方 <strong>“学习”</strong> 选项卡，然后点击进入 <strong>“SOFAServerless 研发框架与产品介绍”</strong>，点击 <strong>“开始学习”</strong>。</p>

</div>



    
      
  
  
  
  

  
  

  

    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-68ec2370d0409cc27325be36693f9368">4 - 用户手册</h1>
    
	
</div>



    
      
  
  
  
  

  
  

  
    
    
	
    

<div class="td-content" style="">
    
	<h1 id="pg-85d651fc55ba7dc800d677008a2c7fa5">4.1 - 基座接入</h1>
    
	
</div>



    
      
  
  
  
  

  
  

  
    
    
	
    

<div class="td-content" style="">
    
	<h1 id="pg-18b872e057bed8156d471e220e894432">4.1.1 - SpringBoot 或 SOFABoot 升级为基座</h1>
    
	<h2 id="前提条件">前提条件</h2>
<ol>
<li>SpringBoot 版本 &gt;= 2.3.0（针对 SpringBoot 用户）</li>
<li>SOFABoot 版本 &gt;= 3.9.0 或 SOFABoot &gt;= 4.0.0（针对 SOFABoot 用户）</li>
</ol>
<h2 id="接入步骤">接入步骤</h2>
<h3 id="代码与配置修改">代码与配置修改</h3>
<h4 id="修改-applicationproperties">修改 application.properties</h4>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-properties" data-lang="properties"><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"># 需要定义应用名</span>
</span></span><span style="display:flex;"><span><span style="color:#c4a000">spring.application.name</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#4e9a06">${替换为实际基座应用名}</span>
</span></span></code></pre></div><h4 id="修改主-pomxml">修改主 pom.xml</h4>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-xml" data-lang="xml"><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">&lt;properties&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;sofa.ark.verion&gt;</span>2.2.5<span style="color:#204a87;font-weight:bold">&lt;/sofa.ark.verion&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;sofa.serverless.runtime.version&gt;</span>0.5.3<span style="color:#204a87;font-weight:bold">&lt;/sofa.serverless.runtime.version&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">&lt;/properties&gt;</span>
</span></span></code></pre></div><div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-xml" data-lang="xml"><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">&lt;dependency&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;groupId&gt;</span>com.alipay.sofa.serverless<span style="color:#204a87;font-weight:bold">&lt;/groupId&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;artifactId&gt;</span>sofa-serverless-base-starter<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;version&gt;</span>${sofa.serverless.runtime.version}<span style="color:#204a87;font-weight:bold">&lt;/version&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">&lt;/dependency&gt;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic">&lt;!-- 如果使用了 springboot web，则加上这个依赖，详细查看https://www.sofastack.tech/projects/sofa-boot/sofa-ark-multi-web-component-deploy/ --&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">&lt;dependency&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;groupId&gt;</span>com.alipay.sofa<span style="color:#204a87;font-weight:bold">&lt;/groupId&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;artifactId&gt;</span>web-ark-plugin<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">&lt;/dependency&gt;</span>
</span></span></code></pre></div><h3 id="启动验证">启动验证</h3>
<p>基座应用能正常启动即表示验证成功！</p>
<br/>
<br/>

</div>



    
	
  

    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-144d016bb7fc7652017580bd4bbe4e56">4.2 - 模块接入</h1>
    
	
</div>



    
      
  
  
  
  

  
  

  
    
    
	
    

<div class="td-content" style="">
    
	<h1 id="pg-efab46696dc71baece82293194586ad3">4.2.1 - SpringBoot 或 SOFABoot 一键升级为模块</h1>
    
	<p>本文讲解了 SpringBoot 或 SOFABoot 一键升级为模块的操作和验证步骤，仅需加一个 ark 打包插件即可实现普通应用一键升级为模块应用，并且能做到同一套代码分支，既能像原来 SpringBoot 一样独立启动，也能作为模块与其它应用合并部署在一起启动。</p>
<h2 id="前提条件">前提条件</h2>
<ol>
<li>SpringBoot 版本 &gt;= 2.3.0（针对 SpringBoot 用户）</li>
<li>SOFABoot &gt;= 3.9.0 或 SOFABoot &gt;= 4.0.0（针对 SOFABoot 用户）</li>
</ol>
<h2 id="接入步骤">接入步骤</h2>
<h3 id="步骤-1修改-applicationproperties">步骤 1：修改 application.properties</h3>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-properties" data-lang="properties"><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"># 需要定义应用名</span>
</span></span><span style="display:flex;"><span><span style="color:#c4a000">spring.application.name</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#4e9a06">${替换为实际模块应用名}</span>
</span></span></code></pre></div><h3 id="步骤-2添加模块需要的依赖和打包插件">步骤 2：添加模块需要的依赖和打包插件</h3>
<p><strong>特别注意</strong>： sofa ark 插件定义顺序必须在 springboot 打包插件前;</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-xml" data-lang="xml"><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">&lt;plugins&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#8f5902;font-style:italic">&lt;!--这里添加ark 打包插件--&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;plugin&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;groupId&gt;</span>com.alipay.sofa<span style="color:#204a87;font-weight:bold">&lt;/groupId&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;artifactId&gt;</span>sofa-ark-maven-plugin<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;version&gt;</span>{sofa.ark.version}<span style="color:#204a87;font-weight:bold">&lt;/version&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;executions&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&lt;execution&gt;</span>
</span></span><span style="display:flex;"><span>                <span style="color:#204a87;font-weight:bold">&lt;id&gt;</span>default-cli<span style="color:#204a87;font-weight:bold">&lt;/id&gt;</span>
</span></span><span style="display:flex;"><span>                <span style="color:#204a87;font-weight:bold">&lt;goals&gt;</span>
</span></span><span style="display:flex;"><span>                    <span style="color:#204a87;font-weight:bold">&lt;goal&gt;</span>repackage<span style="color:#204a87;font-weight:bold">&lt;/goal&gt;</span>
</span></span><span style="display:flex;"><span>                <span style="color:#204a87;font-weight:bold">&lt;/goals&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&lt;/execution&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;/executions&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;configuration&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&lt;skipArkExecutable&gt;</span>true<span style="color:#204a87;font-weight:bold">&lt;/skipArkExecutable&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&lt;outputDirectory&gt;</span>./target<span style="color:#204a87;font-weight:bold">&lt;/outputDirectory&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&lt;bizName&gt;</span>${替换为模块名}<span style="color:#204a87;font-weight:bold">&lt;/bizName&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&lt;webContextPath&gt;</span>${模块自定义的 web context path}<span style="color:#204a87;font-weight:bold">&lt;/webContextPath&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&lt;declaredMode&gt;</span>true<span style="color:#204a87;font-weight:bold">&lt;/declaredMode&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;/configuration&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;/plugin&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#8f5902;font-style:italic">&lt;!--  构建出普通 SpringBoot fatjar，支持独立部署时使用，如果不需要可以删除  --&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;plugin&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#8f5902;font-style:italic">&lt;!--原来 spring-boot 打包插件 --&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;groupId&gt;</span>org.springframework.boot<span style="color:#204a87;font-weight:bold">&lt;/groupId&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;artifactId&gt;</span>spring-boot-maven-plugin<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;/plugin&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">&lt;/plugins&gt;</span>
</span></span></code></pre></div><h3 id="步骤-3自动化瘦身模块">步骤 3：自动化瘦身模块</h3>
<p>您可以使用 ark 打包插件的自动化瘦身能力，自动化瘦身模块应用里的 maven 依赖。这一步是必选的，否则构建出的模块 jar 包会非常大，而且启动会报错。
<em>扩展阅读</em>：如果模块不做依赖瘦身<a href="/docs/faq/import-full-springboot-in-module">独立引入 SpringBoot 框架会怎样？</a></p>
<h3 id="步骤-4构建成模块-jar-包">步骤 4：构建成模块 jar 包</h3>
<p>执行 <code>mvn clean package -DskipTest</code>, 可以在 target 目录下找到打包生成的 ark biz jar 包，也可以在 target/boot 目录下找到打包生成的普通的 springboot jar 包。</p>
<p><strong>小贴士</strong>：<a href="/docs/tutorials/module-development/runtime-compatibility-list/">模块中支持的完整中间件清单</a>。</p>
<h2 id="实验验证模块既能独立启动也能被合并部署">实验：验证模块既能独立启动，也能被合并部署</h2>
<p>增加模块打包插件（sofa-ark-maven-plugin）进行打包后，只会新增 ark-biz.jar 构建产物，与原生 spring-boot-maven-plugin 打包的可执行Jar 互相不冲突、不影响。
当服务器部署时，期望独立启动，就使用原生 spring-boot-maven-plugin 构建出的可执行 Jar 作为构建产物；期望作为 ark 模块部署到基座中时，就使用 sofa-ark-maven-plugin 构建出的 xxx-ark-biz.jar 作为构建产物</p>
<h3 id="验证能合并部署到基座上">验证能合并部署到基座上</h3>
<ol>
<li>启动上一步（验证能独立启动步骤）的基座</li>
<li>发起模块部署</li>
</ol>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span>curl --location --request POST <span style="color:#4e9a06">&#39;localhost:1238/installBiz&#39;</span> <span style="color:#4e9a06">\
</span></span></span><span style="display:flex;"><span><span style="color:#4e9a06"></span>--header <span style="color:#4e9a06">&#39;Content-Type: application/json&#39;</span> <span style="color:#4e9a06">\
</span></span></span><span style="display:flex;"><span><span style="color:#4e9a06"></span>--data <span style="color:#4e9a06">&#39;{
</span></span></span><span style="display:flex;"><span><span style="color:#4e9a06">    &#34;bizName&#34;: &#34;${模块名}&#34;,
</span></span></span><span style="display:flex;"><span><span style="color:#4e9a06">    &#34;bizVersion&#34;: &#34;${模块版本}&#34;,
</span></span></span><span style="display:flex;"><span><span style="color:#4e9a06">    &#34;bizUrl&#34;: &#34;file:///path/to/ark/biz/jar/target/xx-xxxx-ark-biz.jar&#34;
</span></span></span><span style="display:flex;"><span><span style="color:#4e9a06">}&#39;</span>
</span></span></code></pre></div><p>返回如下信息表示模块安装成功<br /><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1695021262517-34e6728e-b39e-4996-855b-d866e839fd0a.png#clientId=ueb52f3f0-186e-4&amp;from=paste&amp;height=226&amp;id=u8ab265a1&amp;originHeight=452&amp;originWidth=1818&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=60390&amp;status=done&amp;style=none&amp;taskId=uf3b43b8e-80dd-43db-b486-3ca38663e5e&amp;title=&amp;width=909" alt="image.png"></p>
<ol start="3">
<li>查看当前模块信息，除了基座 base 以外，还存在一个模块 dynamic-provider</li>
</ol>
<p><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1695021372335-9fbce7ae-ab41-44e8-ab51-6a771bddfef3.png#clientId=ueb52f3f0-186e-4&amp;from=paste&amp;height=367&amp;id=u301dd5fb&amp;originHeight=734&amp;originWidth=1186&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=97949&amp;status=done&amp;style=none&amp;taskId=u8570e201-b10d-460a-946a-d9c94529834&amp;title=&amp;width=593" alt="image.png"></p>
<ol start="4">
<li>卸载模块</li>
</ol>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#a40000">curl</span> <span style="color:#a40000">--location</span> <span style="color:#a40000">--request</span> <span style="color:#a40000">POST</span> <span style="color:#a40000">&#39;localhost:</span><span style="color:#0000cf;font-weight:bold">1238</span><span style="color:#a40000">/uninstallBiz&#39;</span> <span style="color:#a40000">\</span>
</span></span><span style="display:flex;"><span><span style="color:#a40000">--header</span> <span style="color:#a40000">&#39;Content-Type:</span> <span style="color:#a40000">application/json&#39;</span> <span style="color:#a40000">\</span>
</span></span><span style="display:flex;"><span><span style="color:#a40000">--data</span> <span style="color:#a40000">&#39;</span><span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;bizName&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;dynamic-provider&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;bizVersion&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;0.0.1-SNAPSHOT&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#000;font-weight:bold">}</span><span style="color:#a40000">&#39;</span>
</span></span></code></pre></div><p>返回如下，表示卸载成功</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;code&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;SUCCESS&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;data&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;code&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;SUCCESS&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;message&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;Uninstall biz: dynamic-provider:0.0.1-SNAPSHOT success.&#34;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#000;font-weight:bold">}</span>
</span></span><span style="display:flex;"><span><span style="color:#000;font-weight:bold">}</span>
</span></span></code></pre></div><h3 id="验证能独立启动">验证能独立启动</h3>
<p>普通应用改造成模块之后，还是可以独立启动，可以验证一些基本的启动逻辑，只需要在启动配置里勾选自动添加 <code>provided</code>scope 到 classPath 即可，后启动方式与普通应用方式一致。通过自动瘦身改造的模块，也可以在 <code>target/boot</code> 目录下直接通过 springboot jar 包启动，<a href="https://github.com/sofastack/sofa-serverless/blob/module-slimming/samples/springboot-samples/slimming">点击此处</a>查看详情。<br /><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1695032642009-a5248a99-d91b-4420-b830-600b35eaa402.png#clientId=u4eb3445f-d3dc-4&amp;from=paste&amp;height=606&amp;id=ued085b28&amp;originHeight=1212&amp;originWidth=1676&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=169283&amp;status=done&amp;style=none&amp;taskId=u78d21e68-c71c-42d1-ac4c-8b41381bfa4&amp;title=&amp;width=838" alt="image.png"></p>

</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-0f5b7bcef23427d2a6a0c1fcaca9ad4a">4.2.2 - 使用 maven archtype 脚手架自动生成</h1>
    
	<p>正在更新中，预计 11 月上线。</p>

</div>



    
	
  

    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-386a856dc258ab2701435ac4609b80fe">4.3 - 基座与模块并行开发验证</h1>
    
	<p>欢迎使用 <strong>SOFAServerless 完成多 SpringBoot 应用合并部署与动态更新模块</strong>！本文将详细介绍操作流程与方法，希望能够帮助大家节省资源、提高研发效率。
首先，利用 SOFAServerless 完成合并部署与动态更新模块，适用于两种典型场景：</p>
<ol>
<li><strong>合并部署</strong></li>
<li><strong>中台应用</strong><em>（该场景需要先完成合并部署，再完成中台应用 demo)</em></li>
</ol>
<blockquote>
<p>本文实验工程代码在：<a href="https://github.com/sofastack/sofa-serverless/tree/master/samples/springboot-samples/web/tomcat">开源仓库 samples 目录库里</a></p>
</blockquote>
<h2 id="场景一合并部署">场景一：合并部署</h2>
<p>先介绍第一个场景<strong>多应用合并部署</strong>，整体流程如下:
<img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/96256555/1700728867593-5f85b5a6-254c-44f9-9866-03f75cd1a30e.png#clientId=u236ce451-8502-4&amp;from=paste&amp;height=596&amp;id=ud7c32f07&amp;originHeight=1192&amp;originWidth=2386&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=2443895&amp;status=done&amp;style=none&amp;taskId=uf8f160d5-4794-4459-aa18-118e3895bff&amp;title=&amp;width=1193" alt="image.png"></p>
<p>可以看到，整体上需要完成的动作是<strong>基座/模块接入改造后进行开发与验证</strong>，而基座与模块的合并部署动作都是可以并行的。接下来我们将逐步介绍操作细节。</p>
<h3 id="1-基座接入改造">1. 基座接入改造</h3>
<ol>
<li>为 **application.properties **增加应用名（如果没有的话）：</li>
</ol>
<p><code>spring.application.name=${基座应用名}</code></p>
<ol start="2">
<li>在 **pom.xml **里增加必要的依赖</li>
</ol>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-xml" data-lang="xml"><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">&lt;properties&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;sofa.serverless.runtime.version&gt;</span>0.5.3<span style="color:#204a87;font-weight:bold">&lt;/sofa.serverless.runtime.version&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">&lt;/properties&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">&lt;dependencies&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;dependency&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;groupId&gt;</span>com.alipay.sofa.serverless<span style="color:#204a87;font-weight:bold">&lt;/groupId&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;artifactId&gt;</span>sofa-serverless-base-starter<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;version&gt;</span>${sofa.serverless.runtime.version}<span style="color:#204a87;font-weight:bold">&lt;/version&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;/dependency&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">&lt;/dependencies&gt;</span>
</span></span></code></pre></div><hr>
<p>理论上增加这个依赖就可以了，但由于本 demo 需要演示多个 web 模块应用使用一个端口合并部署，需要再引入 <code>web-ark-plugin</code> 依赖，<a href="https://www.sofastack.tech/projects/sofa-boot/sofa-ark-multi-web-component-deploy/">详细原理查看这里</a>。</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-xml" data-lang="xml"><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;dependency&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;groupId&gt;</span>com.alipay.sofa<span style="color:#204a87;font-weight:bold">&lt;/groupId&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;artifactId&gt;</span>web-ark-plugin<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;/dependency&gt;</span>
</span></span></code></pre></div><ol start="3">
<li>点击编译器启动基座。</li>
</ol>
<h3 id="2-模块-1-接入改造">2. 模块 1 接入改造</h3>
<ol>
<li>添加模块需要的依赖和打包插件</li>
</ol>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#a40000">&lt;plugins&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a40000">&lt;!--这里添加ark</span> <span style="color:#a40000">打包插件--&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a40000">&lt;plugin&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#a40000">&lt;groupId&gt;com.alipay.sofa&lt;/groupId&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#a40000">&lt;artifactId&gt;sofa-ark-maven-plugin&lt;/artifactId&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#a40000">&lt;executions&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#a40000">&lt;execution&gt;</span>
</span></span><span style="display:flex;"><span>                <span style="color:#a40000">&lt;id&gt;default-cli&lt;/id&gt;</span>
</span></span><span style="display:flex;"><span>                <span style="color:#a40000">&lt;goals&gt;</span>
</span></span><span style="display:flex;"><span>                    <span style="color:#a40000">&lt;goal&gt;repackage&lt;/goal&gt;</span>
</span></span><span style="display:flex;"><span>                <span style="color:#a40000">&lt;/goals&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#a40000">&lt;/execution&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#a40000">&lt;/executions&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#a40000">&lt;configuration&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#a40000">&lt;skipArkExecutable&gt;</span><span style="color:#204a87;font-weight:bold">true</span><span style="color:#a40000">&lt;/skipArkExecutable&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#a40000">&lt;outputDirectory&gt;./target&lt;/outputDirectory&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#a40000">&lt;bizName&gt;$</span><span style="color:#000;font-weight:bold">{</span><span style="color:#a40000">替换为模块名</span><span style="color:#000;font-weight:bold">}</span><span style="color:#a40000">&lt;/bizName&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#a40000">&lt;webContextPath&gt;$</span><span style="color:#000;font-weight:bold">{</span><span style="color:#a40000">模块自定义的</span> <span style="color:#a40000">web</span> <span style="color:#a40000">context</span> <span style="color:#a40000">path，需要与其他模块不同</span><span style="color:#000;font-weight:bold">}</span><span style="color:#a40000">&lt;/webContextPath&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#a40000">&lt;declaredMode&gt;</span><span style="color:#204a87;font-weight:bold">true</span><span style="color:#a40000">&lt;/declaredMode&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#a40000">&lt;!--</span>  <span style="color:#a40000">配置模块自动排包列表，从</span> <span style="color:#a40000">github</span> <span style="color:#a40000">下载</span> <span style="color:#a40000">rules.txt，并放在模块根目录的</span> <span style="color:#a40000">conf/ark/</span> <span style="color:#a40000">目录下，下载地址：https:</span><span style="color:#8f5902;font-style:italic">//github.com/sofastack/sofa-serverless/blob/master/samples/springboot-samples/slimming/log4j2/biz1/conf/ark/rules.txt  --&gt;
</span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span>            <span style="color:#a40000">&lt;packExcludesConfig&gt;rules.txt&lt;/packExcludesConfig&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#a40000">&lt;/configuration&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a40000">&lt;/plugin&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a40000">&lt;!--</span>  <span style="color:#a40000">构建出普通</span> <span style="color:#a40000">SpringBoot</span> <span style="color:#a40000">fatjar，支持独立部署时使用，如果不需要可以删除</span>  <span style="color:#a40000">--&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a40000">&lt;plugin&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#a40000">&lt;!--原来</span> <span style="color:#a40000">spring-boot</span> <span style="color:#a40000">打包插件</span> <span style="color:#a40000">--&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#a40000">&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#a40000">&lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a40000">&lt;/plugin&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#a40000">&lt;/plugins&gt;</span>
</span></span></code></pre></div><ol start="2">
<li>
<p>参考官网模块瘦身里<a href="https://sofaserverless.gitee.io/docs/tutorials/module-development/module-slimming/#%E4%B8%80%E9%94%AE%E8%87%AA%E5%8A%A8%E7%98%A6%E8%BA%AB">自动排包部分</a>，下载排包配置文件 <strong>rules.txt</strong>，放在在 <strong>conf/ark/</strong> 目录下</p>
</li>
<li>
<p>开发模块，例如增加 Rest Controller，提供 Rest 接口</p>
</li>
</ol>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#a40000">@RestController</span>
</span></span><span style="display:flex;"><span><span style="color:#a40000">public</span> <span style="color:#a40000">class</span> <span style="color:#a40000">SampleController</span> <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a40000">private</span> <span style="color:#a40000">static</span> <span style="color:#a40000">final</span> <span style="color:#a40000">Logger</span> <span style="color:#a40000">LOGGER</span> <span style="color:#a40000">=</span> <span style="color:#a40000">LoggerFactory.getLogger(SampleController.class);</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#a40000">@Autowired</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a40000">private</span> <span style="color:#a40000">ApplicationContext</span> <span style="color:#a40000">applicationContext;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#a40000">@RequestMapping(value</span> <span style="color:#a40000">=</span> <span style="color:#204a87;font-weight:bold">&#34;/&#34;</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#a40000">method</span> <span style="color:#a40000">=</span> <span style="color:#a40000">RequestMethod.GET)</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a40000">public</span> <span style="color:#a40000">String</span> <span style="color:#a40000">hello()</span> <span style="color:#a40000">{</span>
</span></span><span style="display:flex;"><span>        <span style="color:#a40000">String</span> <span style="color:#a40000">appName</span> <span style="color:#a40000">=</span> <span style="color:#a40000">applicationContext.getApplicationName();</span>
</span></span><span style="display:flex;"><span>        <span style="color:#a40000">LOGGER.info(</span><span style="color:#204a87;font-weight:bold">&#34;{} web test: into sample controller&#34;</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#a40000">appName);</span>
</span></span><span style="display:flex;"><span>        <span style="color:#a40000">return</span> <span style="color:#a40000">String.format(</span><span style="color:#204a87;font-weight:bold">&#34;hello to %s deploy&#34;</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#a40000">appName);</span>
</span></span><span style="display:flex;"><span>    <span style="color:#000;font-weight:bold">}</span>
</span></span><span style="display:flex;"><span><span style="color:#a40000">}</span>
</span></span></code></pre></div><ol start="4">
<li>
<p><a href="https://github.com/sofastack/sofa-serverless/releases/tag/arkctl-release-0.1.0">点击这里下载 Arkctl</a>，mac/linux 电脑放入 <code>**/usr/local/bin**</code> 目录中，windows 可以考虑直接放在项目根目录下</p>
</li>
<li>
<p>执行 <code>arkctl deploy</code> 构建部署，成功后 <code>curl localhost:8080/${模块1 web context path}/</code> 验证服务返回。显示正常，进入下一步。</p>
</li>
</ol>
<pre tabindex="0"><code>hello to ${模块1名} deploy
</code></pre><h3 id="3-模块-1-开发与验证">3. 模块 1 开发与验证</h3>
<p>开发与验证需要完成<strong>修改代码并发布 V2 版本</strong>。具体操作如下：</p>
<ol>
<li>修改 Rest 代码</li>
</ol>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#a40000">@RestController</span>
</span></span><span style="display:flex;"><span><span style="color:#a40000">public</span> <span style="color:#a40000">class</span> <span style="color:#a40000">SampleController</span> <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a40000">private</span> <span style="color:#a40000">static</span> <span style="color:#a40000">final</span> <span style="color:#a40000">Logger</span> <span style="color:#a40000">LOGGER</span> <span style="color:#a40000">=</span> <span style="color:#a40000">LoggerFactory.getLogger(SampleController.class);</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#a40000">@Autowired</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a40000">private</span> <span style="color:#a40000">ApplicationContext</span> <span style="color:#a40000">applicationContext;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    <span style="color:#a40000">@RequestMapping(value</span> <span style="color:#a40000">=</span> <span style="color:#204a87;font-weight:bold">&#34;/&#34;</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#a40000">method</span> <span style="color:#a40000">=</span> <span style="color:#a40000">RequestMethod.GET)</span>
</span></span><span style="display:flex;"><span>    <span style="color:#a40000">public</span> <span style="color:#a40000">String</span> <span style="color:#a40000">hello()</span> <span style="color:#a40000">{</span>
</span></span><span style="display:flex;"><span>        <span style="color:#a40000">String</span> <span style="color:#a40000">appName</span> <span style="color:#a40000">=</span> <span style="color:#a40000">applicationContext.getApplicationName();</span>
</span></span><span style="display:flex;"><span>        <span style="color:#a40000">LOGGER.info(</span><span style="color:#204a87;font-weight:bold">&#34;{} web test v2: into sample controller&#34;</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#a40000">appName);</span>
</span></span><span style="display:flex;"><span>        <span style="color:#a40000">return</span> <span style="color:#a40000">String.format(</span><span style="color:#204a87;font-weight:bold">&#34;hello to %s deploy v2&#34;</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#a40000">appName);</span>
</span></span><span style="display:flex;"><span>    <span style="color:#000;font-weight:bold">}</span>
</span></span><span style="display:flex;"><span><span style="color:#a40000">}</span>
</span></span></code></pre></div><ol start="2">
<li>执行 <code>arkctl deploy</code> 构建部署，成功后 <code>curl localhost:8080/${模块1 web context path}/</code> 验证服务返回</li>
</ol>
<pre tabindex="0"><code>hello to ${模块1名} deploy v2
</code></pre><h3 id="4-模块-2-接入改造开发与验证">4. 模块 2 接入改造、开发与验证</h3>
<p>模块 2 同样采用上述步骤2⃣️3⃣️，即模块 1 接入改造与验证的操作流程。</p>
<h2 id="场景二中台应用">场景二：中台应用</h2>
<p>中台应用的特点是<strong>基座有复杂的编排逻辑</strong>去定义<strong>对外暴露服务和业务所需的 SPI</strong>。模块应用来实现这些 SPI 接口，往往会对一个接口在多个模块里定义多个不同的实现。整体流程如下：
<img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/96256555/1700706388244-f46fbd3d-262d-4a9d-894a-243782860cce.png#clientId=ue666f90d-083a-4&amp;from=paste&amp;height=310&amp;id=u76e59b07&amp;originHeight=620&amp;originWidth=1762&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=345022&amp;status=done&amp;style=none&amp;taskId=ue115f7a7-de5a-4c01-91d4-0965c2422dc&amp;title=&amp;width=881" alt="image.png"></p>
<p>可以看到，与场景一合并部署操作不同的是，需要在<strong>基座</strong>接入改造与开发验证中间新增一步<strong>通信类和 SPI 的定义</strong>；<strong>模块</strong>接入改造与开发验证中间新增一步<strong>引入通信类基座并实现基座 SPI</strong>。
<strong>接下来我们将介绍与合并部署不同的</strong><em><strong>（即新增的）</strong></em><strong>操作细节。</strong></p>
<h3 id="1-基座完成通信类和-spi-的定义">1. 基座完成通信类和 SPI 的定义</h3>
<p>在合并部署接入改造的基础上，需要完成通信类和 SPI 的定义。
通信类需要以 **独立 bundle **的方式存在，才能被模块引入。可参考以下方式：</p>
<ol>
<li>新建 bundle，定义接口类</li>
</ol>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-xml" data-lang="xml"><span style="display:flex;"><span>public class ProductInfo {
</span></span><span style="display:flex;"><span>    private String  name;
</span></span><span style="display:flex;"><span>    private String  author;
</span></span><span style="display:flex;"><span>    private String  src;
</span></span><span style="display:flex;"><span>    private Integer orderCount;
</span></span><span style="display:flex;"><span>}
</span></span></code></pre></div><ol start="2">
<li>定义 SPI</li>
</ol>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">interface</span> <span style="color:#000">StrategyService</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#000">List</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">ProductInfo</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">strategy</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">List</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">ProductInfo</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">products</span><span style="color:#000;font-weight:bold">);</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#000">String</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">getAppName</span><span style="color:#000;font-weight:bold">();</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span></code></pre></div><h3 id="2-模块-1-引入通信类基座并实现基座-spi">2. 模块 1 <strong>引入通信类基座并实现基座 SPI</strong></h3>
<p>在上文合并部署模块 1 接入改造 demo 的基础上，引入通信类，然后定义 SPI 实现。</p>
<ol>
<li>引入通信类和对应 SPI 定义，只需要<strong>在 pom 里引入基座定义的通信 bundle</strong></li>
<li>定义 SPI 实现</li>
</ol>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#5c35cc;font-weight:bold">@Service</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">class</span> <span style="color:#000">StrategyServiceImpl</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">implements</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">StrategyService</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#5c35cc;font-weight:bold">@Autowired</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">private</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">ApplicationContext</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">applicationContext</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#5c35cc;font-weight:bold">@Override</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">List</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">ProductInfo</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">strategy</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">List</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">ProductInfo</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">products</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">return</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">products</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#5c35cc;font-weight:bold">@Override</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">String</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">getAppName</span><span style="color:#000;font-weight:bold">()</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">return</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">applicationContext</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">getApplicationName</span><span style="color:#000;font-weight:bold">();</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span></code></pre></div><ol start="3">
<li>执行 <code>arkctl deploy</code> 构建部署，成功后用 <code>curl localhost:8080/${基座服务入口}/biz1/</code> 验证服务返回</li>
</ol>
<p><strong>biz1</strong> 传入是为了使基座根据不同的参数找到不同的 SPI 实现，执行不同的逻辑。传入的方式可以有很多种，这里用最简单方式——从 **path **里传入。</p>
<pre tabindex="0"><code>默认的 products 列表
</code></pre><h3 id="3-模块-2-引入通信类基座并实现基座-spi">3. 模块 2 <strong>引入通信类基座并实现基座 SPI</strong></h3>
<p>与模块 1 操作相同，需要注意执行 <code>arkctl deploy</code> 构建部署时，成功后 <code>curl localhost:8080/${基座服务入口}/biz2/</code> 验证服务返回。同理，**biz2 **传入是为了基座根据不同的参数，找到不同的 SPI 实现，执行不同逻辑。</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#5c35cc;font-weight:bold">@Service</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">class</span> <span style="color:#000">StrategyServiceImpl</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">implements</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">StrategyService</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#5c35cc;font-weight:bold">@Autowired</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">private</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">ApplicationContext</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">applicationContext</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#5c35cc;font-weight:bold">@Override</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">List</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">ProductInfo</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">strategy</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">List</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">ProductInfo</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">products</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">Collections</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">sort</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">products</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">m</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">n</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">-&gt;</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">n</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">getOrderCount</span><span style="color:#000;font-weight:bold">()</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">-</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">m</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">getOrderCount</span><span style="color:#000;font-weight:bold">());</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">products</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">stream</span><span style="color:#000;font-weight:bold">().</span><span style="color:#c4a000">forEach</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">p</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">-&gt;</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">p</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">setName</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">p</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">getName</span><span style="color:#000;font-weight:bold">()</span><span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#4e9a06">&#34;(&#34;</span><span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#000">p</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">getOrderCount</span><span style="color:#000;font-weight:bold">()</span><span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#4e9a06">&#34;)&#34;</span><span style="color:#000;font-weight:bold">));</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">return</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">products</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#5c35cc;font-weight:bold">@Override</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">String</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">getAppName</span><span style="color:#000;font-weight:bold">()</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">return</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">applicationContext</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">getApplicationName</span><span style="color:#000;font-weight:bold">();</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span></code></pre></div><pre tabindex="0"><code>更改排序后的 products 列表
</code></pre><p>基于上述操作，就可以继续进行上文中模块 <a href="https://sofaserverless.gitee.io/docs/tutorials/trial_step_by_step/"><strong>开发与验证</strong></a> 的操作了。整体流程丝滑易上手，欢迎试用！</p>
<h2 id="文档中的链接地址">文档中的链接地址</h2>
<ol>
<li>本实验工程样例地址：<a href="https://github.com/sofastack/sofa-serverless/tree/master/samples/springboot-samples/web/tomcat">https://github.com/sofastack/sofa-serverless/tree/master/samples/springboot-samples/web/tomcat</a></li>
<li><code>web-ark-plugin</code> 原理： <a href="https://www.sofastack.tech/projects/sofa-boot/sofa-ark-multi-web-component-deploy/">https://www.sofastack.tech/projects/sofa-boot/sofa-ark-multi-web-component-deploy/</a></li>
<li>自动排包原理与配置文件下载：<a href="https://sofaserverless.gitee.io/docs/tutorials/module-development/module-slimming/#%E4%B8%80%E9%94%AE%E8%87%AA%E5%8A%A8%E7%98%A6%E8%BA%AB">https://sofaserverless.gitee.io/docs/tutorials/module-development/module-slimming/#%E4%B8%80%E9%94%AE%E8%87%AA%E5%8A%A8%E7%98%A6%E8%BA%AB</a></li>
<li>Arkctl 下载地址：<a href="https://github.com/sofastack/sofa-serverless/releases/tag/arkctl-release-0.1.0">https://github.com/sofastack/sofa-serverless/releases/tag/arkctl-release-0.1.0</a></li>
<li>本文档地址：<a href="https://sofaserverless.gitee.io/docs/tutorials/trial_step_by_step/">https://sofaserverless.gitee.io/docs/tutorials/trial_step_by_step/</a></li>
</ol>

</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-1338dd6d363fcbe1552c858a20719417">4.4 - 模块研发</h1>
    
	
</div>



    
      
  
  
  
  

  
  

  
    
    
	
    

<div class="td-content" style="">
    
	<h1 id="pg-bf65e93b734e75f456eb02447ae9f065">4.4.1 - 编码规范</h1>
    
	<h2 id="基础规范">基础规范</h2>
<ol>
<li>SOFAServerless 模块中官方验证并兼容的中间件客户端列表<a href="/docs/tutorials/module-operation/runtime-compatibility-list">详见此处</a>。基座中可以使用任意中间件客户端。</li>
<li>如果使用了模块热卸载能力，模块自定义的 Timer、ThreadPool 等需要在模块<strong>卸载时手动清理</strong>。您可以监听 Spring 的 <strong>ContextClosedEvent</strong> 事件，在事件处理函数中清理必要资源，也可以在 Spring XML 定义 Timer、ThreadPool 的地方指定它们的 <strong>destroy-method，<strong>在模块卸载时，Spring 会自动执行</strong> destroy-method</strong>。</li>
<li>基座启动时会部署所有模块，所以基座编码时，一定要向所有模块兼容，否则基座会发布失败。如果遇到无法绕过的不兼容变更（一般是在模块拆分过程中会有比较多的基座与模块不兼容变更），请参见<a href="/docs/tutorials/module-operation/incompatible-base-and-module-upgrade">基座与模块不兼容发布</a>。</li>
</ol>
<h2 id="知识点">知识点</h2>
<p><a href="../module-slimming">模块瘦身</a>  (重要)<br />
<a href="https://www.sofastack.tech/projects/sofa-boot/sofa-ark-ark-jvm/">模块与模块、模块与基座通信</a>  (重要)<br />
<a href="../module-debug">模块测试</a>  (重要)<br />
<a href="../reuse-base-interceptor">模块复用基座拦截器</a><br />
<a href="../reuse-base-datasource">模块复用基座数据源</a><br />
<a href="/docs/introduction/architecture/class-delegation-principle">基座与模块间类委托加载原理介绍</a></p>
<br/>
<br/>

</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-6e3cbd7799f1397ab7793638f56a6f1a">4.4.2 - 模块瘦身</h1>
    
	<h2 id="为什么要瘦身">为什么要瘦身</h2>
<p>为了让模块安装更快、内存消耗更小：</p>
<ul>
<li>提高模块安装的速度，减少模块包大小，减少启动依赖，控制模块安装耗时 &lt; 30秒，甚至 &lt; 5秒。</li>
<li>模块启动后 Spring 上下文中会创建很多对象，如果启用了模块热卸载，可能无法完全回收，安装次数过多会造成 Old 区、Metaspace 区开销大，触发频繁 FullGC，所有要控制单模块包大小 &lt; 5MB。<strong>这样不替换或重启基座也能热部署热卸载数百次。</strong></li>
</ul>
<h2 id="一键自动瘦身">一键自动瘦身</h2>
<h3 id="瘦身原则">瘦身原则</h3>
<p>构建 ark-biz jar 包的原则是，在保证模块功能的前提下，将框架、中间件等通用的包尽量放置到基座中，模块中复用基座的包，这样打出的 ark-biz jar 会更加轻量。在复杂应用中，为了更好的使用模块自动瘦身功能，需要在模块瘦身配置 (模块根目录/conf/ark/文件名.txt) 中，在样例给出的配置名单的基础上，按照既定格式，排除更多的通用依赖包。</p>
<h3 id="步骤一">步骤一</h3>
<p>在「模块项目根目录/conf/ark/文件名.txt」中（比如：my-module/conf/ark/rules.txt），按照如下格式配置需要下沉到基座的框架和中间件常用包。您也可以直接复制<a href="https://github.com/sofastack/sofa-serverless/blob/module-slimming/samples/springboot-samples/slimming/log4j2/biz1/conf/ark/rules.txt">默认的 rules.txt 文件内容</a>到您的项目中。</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-xml" data-lang="xml"><span style="display:flex;"><span>excludeGroupIds=org.apache*
</span></span><span style="display:flex;"><span>excludeArtifactIds=commons-lang
</span></span></code></pre></div><h3 id="步骤二">步骤二</h3>
<p>在模块打包插件中，引入上述配置文件：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-xml" data-lang="xml"><span style="display:flex;"><span>    <span style="color:#8f5902;font-style:italic">&lt;!-- 插件1：打包插件为 sofa-ark biz 打包插件，打包成 ark biz jar --&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;plugin&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;groupId&gt;</span>com.alipay.sofa<span style="color:#204a87;font-weight:bold">&lt;/groupId&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;artifactId&gt;</span>sofa-ark-maven-plugin<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;version&gt;</span>2.2.5<span style="color:#204a87;font-weight:bold">&lt;/version&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;executions&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&lt;execution&gt;</span>
</span></span><span style="display:flex;"><span>                <span style="color:#204a87;font-weight:bold">&lt;id&gt;</span>default-cli<span style="color:#204a87;font-weight:bold">&lt;/id&gt;</span>
</span></span><span style="display:flex;"><span>                <span style="color:#204a87;font-weight:bold">&lt;goals&gt;</span>
</span></span><span style="display:flex;"><span>                    <span style="color:#204a87;font-weight:bold">&lt;goal&gt;</span>repackage<span style="color:#204a87;font-weight:bold">&lt;/goal&gt;</span>
</span></span><span style="display:flex;"><span>                <span style="color:#204a87;font-weight:bold">&lt;/goals&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&lt;/execution&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;/executions&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;configuration&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&lt;skipArkExecutable&gt;</span>true<span style="color:#204a87;font-weight:bold">&lt;/skipArkExecutable&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&lt;outputDirectory&gt;</span>./target<span style="color:#204a87;font-weight:bold">&lt;/outputDirectory&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&lt;bizName&gt;</span>biz1<span style="color:#204a87;font-weight:bold">&lt;/bizName&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#8f5902;font-style:italic">&lt;!-- packExcludesConfig	模块瘦身配置，文件名自定义，和配置对应即可--&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#8f5902;font-style:italic">&lt;!--					配置文件位置：biz1/conf/ark/rules.txt--&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&lt;packExcludesConfig&gt;</span>rules.txt<span style="color:#204a87;font-weight:bold">&lt;/packExcludesConfig&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&lt;webContextPath&gt;</span>biz1<span style="color:#204a87;font-weight:bold">&lt;/webContextPath&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&lt;declaredMode&gt;</span>true<span style="color:#204a87;font-weight:bold">&lt;/declaredMode&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#8f5902;font-style:italic">&lt;!--					打包、安装和发布 ark biz--&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#8f5902;font-style:italic">&lt;!--					静态合并部署需要配置--&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#8f5902;font-style:italic">&lt;!--					&lt;attach&gt;true&lt;/attach&gt;--&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;/configuration&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;/plugin&gt;</span>
</span></span></code></pre></div><h3 id="步骤三">步骤三</h3>
<p>打包构建出模块 ark-biz jar 包即可，您可以明显看出瘦身后的 ark-biz jar 包大小差异。</p>
<p>您可<a href="https://github.com/sofastack/sofa-serverless/tree/master/samples/springboot-samples/slimming">点击此处</a>查看完整模块瘦身样例工程。您也可以阅读下文继续了解模块的瘦身原理。</p>
<h2 id="基本原理">基本原理</h2>
<p>SOFAServerless 底层借助 SOFAArk 框架，实现了模块之间、模块和基座之间的相互隔离，以下两个核心逻辑对编码非常重要，需要深刻理解：</p>
<ol>
<li>基座有独立的类加载器和 Spring 上下文，模块也有<strong>独立的类加载器</strong>和** Spring 上下文**，相互之间 Spring 上下文都是<strong>隔离的</strong>。</li>
<li>模块启动时会初始化各种对象，会<strong>优先使用模块的类加载器</strong>去加载构建产物 FatJar 中的 class、resource 和 Jar 包，<strong>找不到的类会委托基座的类加载器</strong>去查找。</li>
</ol>
<p><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/jpeg/8276/1678275655551-75bf283f-3817-447a-84b2-7f6f7f773300.jpeg" alt=""></p>
<p>基于这套类委托的加载机制，让基座和模块共用的 class、resource 和 Jar 包<strong>通通下沉</strong>到基座中，可以让模块构建产物<strong>非常小</strong>，更重要的是还能让模块在运行中大量复用基座已有的 class、bean、service、IO 连接池、线程池等资源，从而模块消耗的内存<strong>非常少</strong>，启动也能<strong>非常快</strong>。<br />所谓模块瘦身，就是让基座已经有的 Jar 依赖务必在模块中剔除干净，在主 pom.xml 和 bootstrap/pom.xml 将共用的 Jar 包 <strong>scope 都声明为 provided</strong>，让其不参与打包构建。</p>
<h2 id="手动排包瘦身">手动排包瘦身</h2>
<p>模块运行时装载类时，会优先从自己的依赖里找，找不到的话再委托基座的 ClassLoader 去加载。<br />所以对于基座已经存在的依赖，在模块 pom 里将其 scope 设置成 provided，避免其参与模块打包。<br /><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/8276/1678276103445-036d226e-4f88-40bc-937d-90fd4c60b83d.png#clientId=udf1ce5b3-f5a9-4&amp;from=paste&amp;height=521&amp;id=jFiln&amp;originHeight=1042&amp;originWidth=1848&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=957278&amp;status=done&amp;style=none&amp;taskId=u254c8709-de81-4175-bcf8-f1c4a26bc49&amp;title=&amp;width=924" alt="image.png"></p>
<p>如果要排除的依赖无法找到，可以利用 <strong>maven helper 插件</strong>找到其直接依赖。举个例子，图示中要排除的依赖为 spring-boot-autoconfigure，右边的直接依赖有 sofa-boot-alipay-runtime，ddcs-alipay-sofa-boot-starter等（只需要看 scope 为 compile 的依赖）：<br /><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/191604/1691733668683-34a9d11f-3ca6-4b66-a4e3-22ade9413094.png#clientId=u05d65c58-49f7-4&amp;from=paste&amp;height=869&amp;id=u467da8b5&amp;originHeight=1738&amp;originWidth=2644&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=1043897&amp;status=done&amp;style=none&amp;taskId=u70530c01-d7a5-4ca9-875d-3785f59242b&amp;title=&amp;width=1322" alt="image.png"><br />确定自己代码 pom.xml 中有 ddcs-alipay-sofa-boot-starter，增加 exlcusions 来排除依赖：<br /><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/191604/1691735644585-9201c203-b749-46e9-ab96-49ecc8090098.png#clientId=uda997d0f-c9aa-4&amp;from=paste&amp;height=244&amp;id=ub08bbabe&amp;originHeight=488&amp;originWidth=1476&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=85290&amp;status=done&amp;style=none&amp;taskId=u7f72a9d1-a1cd-422e-a50a-beafc4a9c4a&amp;title=&amp;width=738" alt="image.png"></p>
<h2 id="在-pom-中统一排包更彻底">在 pom 中统一排包（更彻底）</h2>
<p>有些依赖引入了过多的间接依赖，手动排查比较困难，此时可以通过通配符匹配，把那些中间件、基座的依赖全部剔除掉，如 org.apache.commons、org.springframework 等等，这种方式会把间接依赖都排除掉，相比使用 sofa-ark-maven-plugin 排包效率会更高：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-xml" data-lang="xml"><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">&lt;dependency&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;groupId&gt;</span>com.serverless.mymodule<span style="color:#204a87;font-weight:bold">&lt;/groupId&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;artifactId&gt;</span>mymodule-core<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;exclusions&gt;</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&lt;exclusion&gt;</span>
</span></span><span style="display:flex;"><span>              <span style="color:#204a87;font-weight:bold">&lt;groupId&gt;</span>org.springframework<span style="color:#204a87;font-weight:bold">&lt;/groupId&gt;</span>
</span></span><span style="display:flex;"><span>              <span style="color:#204a87;font-weight:bold">&lt;artifactId&gt;</span>*<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&lt;/exclusion&gt;</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&lt;exclusion&gt;</span>
</span></span><span style="display:flex;"><span>              <span style="color:#204a87;font-weight:bold">&lt;groupId&gt;</span>org.apache.commons<span style="color:#204a87;font-weight:bold">&lt;/groupId&gt;</span>
</span></span><span style="display:flex;"><span>              <span style="color:#204a87;font-weight:bold">&lt;artifactId&gt;</span>*<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&lt;/exclusion&gt;</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&lt;exclusion&gt;</span>
</span></span><span style="display:flex;"><span>              <span style="color:#204a87;font-weight:bold">&lt;groupId&gt;</span>......<span style="color:#204a87;font-weight:bold">&lt;/groupId&gt;</span>
</span></span><span style="display:flex;"><span>              <span style="color:#204a87;font-weight:bold">&lt;artifactId&gt;</span>*<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&lt;/exclusion&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;/exclusions&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">&lt;/dependency&gt;</span>
</span></span></code></pre></div><h2 id="在-sofa-ark-maven-plugin-中指定排包">在 sofa-ark-maven-plugin 中指定排包</h2>
<p>通过使用 **excludeGroupIds、excludeGroupIds **能够排除大量基座上已有的公共依赖：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-xml" data-lang="xml"><span style="display:flex;"><span> <span style="color:#204a87;font-weight:bold">&lt;plugin&gt;</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&lt;groupId&gt;</span>com.alipay.sofa<span style="color:#204a87;font-weight:bold">&lt;/groupId&gt;</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&lt;artifactId&gt;</span>sofa-ark-maven-plugin<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&lt;executions&gt;</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&lt;execution&gt;</span>
</span></span><span style="display:flex;"><span>              <span style="color:#204a87;font-weight:bold">&lt;id&gt;</span>default-cli<span style="color:#204a87;font-weight:bold">&lt;/id&gt;</span>
</span></span><span style="display:flex;"><span>              <span style="color:#204a87;font-weight:bold">&lt;goals&gt;</span>
</span></span><span style="display:flex;"><span>                  <span style="color:#204a87;font-weight:bold">&lt;goal&gt;</span>repackage<span style="color:#204a87;font-weight:bold">&lt;/goal&gt;</span>
</span></span><span style="display:flex;"><span>              <span style="color:#204a87;font-weight:bold">&lt;/goals&gt;</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&lt;/execution&gt;</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&lt;/executions&gt;</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&lt;configuration&gt;</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&lt;excludeGroupIds&gt;</span>io.netty,org.apache.commons,......<span style="color:#204a87;font-weight:bold">&lt;/excludeGroupIds&gt;</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&lt;excludeArtifactIds&gt;</span>validation-api,fastjson,hessian,slf4j-api,junit,velocity,......<span style="color:#204a87;font-weight:bold">&lt;/excludeArtifactIds&gt;</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&lt;outputDirectory&gt;</span>../../target<span style="color:#204a87;font-weight:bold">&lt;/outputDirectory&gt;</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&lt;bizName&gt;</span>mymodule<span style="color:#204a87;font-weight:bold">&lt;/bizName&gt;</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&lt;finalName&gt;</span>mymodule-${project.version}-${timestamp}<span style="color:#204a87;font-weight:bold">&lt;/finalName&gt;</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&lt;bizVersion&gt;</span>${project.version}-${timestamp}<span style="color:#204a87;font-weight:bold">&lt;/bizVersion&gt;</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&lt;webContextPath&gt;</span>/mymodule<span style="color:#204a87;font-weight:bold">&lt;/webContextPath&gt;</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&lt;/configuration&gt;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#204a87;font-weight:bold">&lt;/plugin&gt;</span>
</span></span></code></pre></div><br/>
<br/>

</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-66b2590d54145be7fd0f895684bc34ef">4.4.3 - 模块与模块、模块与基座通信</h1>
    
	<p>基座与模块之间、模块与模块之间存在 spring 上下文隔离，互相的 bean 不会冲突、不可见。然而很多应用场景比如中台模式、独立模块模式等存在基座调用模块、模块调用基座、模块与模块互相调用的场景。
当前支持3种方式调用，@AutowiredFromBiz, @AutowiredFromBase, SpringServiceFinder 方法调用，注意三个方式使用的情况不同。</p>
<h1 id="spring-环境">Spring 环境</h1>
<h2 id="基座调用模块">基座调用模块</h2>
<p>只能使用 SpringServiceFinder</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#5c35cc;font-weight:bold">@RestController</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">class</span> <span style="color:#000">SampleController</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#5c35cc;font-weight:bold">@RequestMapping</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">value</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;/&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">method</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">RequestMethod</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">GET</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">String</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">hello</span><span style="color:#000;font-weight:bold">()</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">Provider</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">studentProvider</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">SpringServiceFinder</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">getModuleService</span><span style="color:#000;font-weight:bold">(</span><span style="color:#4e9a06">&#34;biz&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;0.0.1-SNAPSHOT&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">                </span><span style="color:#4e9a06">&#34;studentProvider&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Provider</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">class</span><span style="color:#000;font-weight:bold">);</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">Result</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">result</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">studentProvider</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">provide</span><span style="color:#000;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">new</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Param</span><span style="color:#000;font-weight:bold">());</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">Provider</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">teacherProvider</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">SpringServiceFinder</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">getModuleService</span><span style="color:#000;font-weight:bold">(</span><span style="color:#4e9a06">&#34;biz&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;0.0.1-SNAPSHOT&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">                </span><span style="color:#4e9a06">&#34;teacherProvider&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Provider</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">class</span><span style="color:#000;font-weight:bold">);</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">Result</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">result1</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">teacherProvider</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">provide</span><span style="color:#000;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">new</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Param</span><span style="color:#000;font-weight:bold">());</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">Map</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Provider</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">providerMap</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">SpringServiceFinder</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">listModuleServices</span><span style="color:#000;font-weight:bold">(</span><span style="color:#4e9a06">&#34;biz&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;0.0.1-SNAPSHOT&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">                </span><span style="color:#000">Provider</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">class</span><span style="color:#000;font-weight:bold">);</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">for</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">String</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">beanName</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">providerMap</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">keySet</span><span style="color:#000;font-weight:bold">())</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">            </span><span style="color:#000">Result</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">result2</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">providerMap</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">get</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">beanName</span><span style="color:#000;font-weight:bold">).</span><span style="color:#c4a000">provide</span><span style="color:#000;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">new</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Param</span><span style="color:#000;font-weight:bold">());</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">return</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;hello to ark master biz&#34;</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span></code></pre></div><h2 id="模块调用基座">模块调用基座</h2>
<h3 id="方式一注解-autowiredfrombase">方式一：注解 @AutowiredFromBase</h3>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#5c35cc;font-weight:bold">@RestController</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">class</span> <span style="color:#000">SampleController</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#5c35cc;font-weight:bold">@AutowiredFromBase</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">name</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;sampleServiceImplNew&#34;</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">private</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">SampleService</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">sampleServiceImplNew</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#5c35cc;font-weight:bold">@AutowiredFromBase</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">name</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;sampleServiceImpl&#34;</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">private</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">SampleService</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">sampleServiceImpl</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#5c35cc;font-weight:bold">@AutowiredFromBase</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">private</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">List</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">SampleService</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">sampleServiceList</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#5c35cc;font-weight:bold">@AutowiredFromBase</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">private</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Map</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">SampleService</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">sampleServiceMap</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#5c35cc;font-weight:bold">@AutowiredFromBase</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">private</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">AppService</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">appService</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#5c35cc;font-weight:bold">@RequestMapping</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">value</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;/&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">method</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">RequestMethod</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">GET</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">String</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">hello</span><span style="color:#000;font-weight:bold">()</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">sampleServiceImplNew</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">service</span><span style="color:#000;font-weight:bold">();</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">sampleServiceImpl</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">service</span><span style="color:#000;font-weight:bold">();</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">for</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">SampleService</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">sampleService</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">sampleServiceList</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">            </span><span style="color:#000">sampleService</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">service</span><span style="color:#000;font-weight:bold">();</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">for</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">String</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">beanName</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">sampleServiceMap</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">keySet</span><span style="color:#000;font-weight:bold">())</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">            </span><span style="color:#000">sampleServiceMap</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">get</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">beanName</span><span style="color:#000;font-weight:bold">).</span><span style="color:#c4a000">service</span><span style="color:#000;font-weight:bold">();</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">appService</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">getAppName</span><span style="color:#000;font-weight:bold">();</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">return</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;hello to ark2 dynamic deploy&#34;</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span></code></pre></div><h3 id="方式二编程api-springservicefinder">方式二：编程API SpringServiceFinder</h3>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#5c35cc;font-weight:bold">@RestController</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">class</span> <span style="color:#000">SampleController</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#5c35cc;font-weight:bold">@RequestMapping</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">value</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;/&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">method</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">RequestMethod</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">GET</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">String</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">hello</span><span style="color:#000;font-weight:bold">()</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">SampleService</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">sampleServiceImplFromFinder</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">SpringServiceFinder</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">getBaseService</span><span style="color:#000;font-weight:bold">(</span><span style="color:#4e9a06">&#34;sampleServiceImpl&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">SampleService</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">class</span><span style="color:#000;font-weight:bold">);</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">String</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">result</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">sampleServiceImplFromFinder</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">service</span><span style="color:#000;font-weight:bold">();</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">System</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">out</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">println</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">result</span><span style="color:#000;font-weight:bold">);</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">Map</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">SampleService</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">sampleServiceMapFromFinder</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">SpringServiceFinder</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">listBaseServices</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">SampleService</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">class</span><span style="color:#000;font-weight:bold">);</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">for</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">String</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">beanName</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">sampleServiceMapFromFinder</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">keySet</span><span style="color:#000;font-weight:bold">())</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">            </span><span style="color:#000">String</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">result1</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">sampleServiceMapFromFinder</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">get</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">beanName</span><span style="color:#000;font-weight:bold">).</span><span style="color:#c4a000">service</span><span style="color:#000;font-weight:bold">();</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">            </span><span style="color:#000">System</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">out</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">println</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">result1</span><span style="color:#000;font-weight:bold">);</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">return</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;hello to ark2 dynamic deploy&#34;</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span></code></pre></div><h2 id="模块调用模块">模块调用模块</h2>
<p>参考模块调用基座，注解使用 @AutowiredFromBiz 和 编程API支持 SpringServiceFinder。</p>
<h3 id="方式一注解-autowiredfrombiz">方式一：注解 @AutowiredFromBiz</h3>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#5c35cc;font-weight:bold">@RestController</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">class</span> <span style="color:#000">SampleController</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#5c35cc;font-weight:bold">@AutowiredFromBiz</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">bizName</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;biz&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">bizVersion</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;0.0.1-SNAPSHOT&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">name</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;studentProvider&#34;</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">private</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Provider</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">studentProvider</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#5c35cc;font-weight:bold">@AutowiredFromBiz</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">bizName</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;biz&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">name</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;teacherProvider&#34;</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">private</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Provider</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">teacherProvider</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#5c35cc;font-weight:bold">@AutowiredFromBiz</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">bizName</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;biz&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">bizVersion</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;0.0.1-SNAPSHOT&#34;</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">private</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">List</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">Provider</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">providers</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#5c35cc;font-weight:bold">@RequestMapping</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">value</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;/&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">method</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">RequestMethod</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">GET</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">String</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">hello</span><span style="color:#000;font-weight:bold">()</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">Result</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">provide</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">studentProvider</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">provide</span><span style="color:#000;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">new</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Param</span><span style="color:#000;font-weight:bold">());</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">Result</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">provide1</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">teacherProvider</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">provide</span><span style="color:#000;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">new</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Param</span><span style="color:#000;font-weight:bold">());</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">for</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">Provider</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">provider</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">providers</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">            </span><span style="color:#000">Result</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">provide2</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">provider</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">provide</span><span style="color:#000;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">new</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Param</span><span style="color:#000;font-weight:bold">());</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">return</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;hello to ark2 dynamic deploy&#34;</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span></code></pre></div><h3 id="方式二编程api-springservicefinder-1">方式二：编程API SpringServiceFinder</h3>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#5c35cc;font-weight:bold">@RestController</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">class</span> <span style="color:#000">SampleController</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#5c35cc;font-weight:bold">@RequestMapping</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">value</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;/&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">method</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">RequestMethod</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">GET</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">String</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">hello</span><span style="color:#000;font-weight:bold">()</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">Provider</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">teacherProvider1</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">SpringServiceFinder</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">getModuleService</span><span style="color:#000;font-weight:bold">(</span><span style="color:#4e9a06">&#34;biz&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;0.0.1-SNAPSHOT&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;teacherProvider&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Provider</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">class</span><span style="color:#000;font-weight:bold">);</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">Result</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">result1</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">teacherProvider1</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">provide</span><span style="color:#000;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">new</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Param</span><span style="color:#000;font-weight:bold">());</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">Map</span><span style="color:#ce5c00;font-weight:bold">&lt;</span><span style="color:#000">String</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Provider</span><span style="color:#ce5c00;font-weight:bold">&gt;</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">providerMap</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">SpringServiceFinder</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">listModuleServices</span><span style="color:#000;font-weight:bold">(</span><span style="color:#4e9a06">&#34;biz&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;0.0.1-SNAPSHOT&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Provider</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">class</span><span style="color:#000;font-weight:bold">);</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">for</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">String</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">beanName</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">providerMap</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">keySet</span><span style="color:#000;font-weight:bold">())</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">            </span><span style="color:#000">Result</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">result2</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">providerMap</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">get</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">beanName</span><span style="color:#000;font-weight:bold">).</span><span style="color:#c4a000">provide</span><span style="color:#000;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">new</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Param</span><span style="color:#000;font-weight:bold">());</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">return</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;hello to ark2 dynamic deploy&#34;</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span></code></pre></div><p><a href="https://github.com/sofastack/sofa-serverless/tree/master/samples">完整样例</a></p>
<h1 id="sofaboot-环境">SOFABoot 环境</h1>
<p><a href="https://www.sofastack.tech/projects/sofa-boot/sofa-ark-ark-jvm/">请参考该文档</a></p>
<br/>
<br/>

</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-e829d04a9debc230b4d695f03971b67b">4.4.4 - 模块本地开发</h1>
    
	<h2 id="arkctl-工具安装">Arkctl 工具安装</h2>
<p>Arkctl 模块安装主要提供自动打包和部署能力，自动打包调用 mvn 命令构建模块 jar包，自动部署调用 <a href="/docs/contribution-guidelines/arklet/architecture/">arklet</a> 提供的 api 接口进行部署。如果不想使用命令行工具，也可以直接使用 arklet 提供的 api 接口发起部署操作。</p>
<p>方法一：</p>
<ol>
<li>本地安装 go 环境，go 依赖版本在 1.21 以上。</li>
<li>执行 go install <code>todo 独立的 arkctl go 仓库</code> 命令，安装 arkctl 工具。</li>
</ol>
<p>方法二：</p>
<ol>
<li>在 [二进制列表](<a href="https://github.com/sofastack/sofa-serverless/releases/tag/arkctl-release-0.1.0">https://github.com/sofastack/sofa-serverless/releases/tag/arkctl-release-0.1.0</a> 中下载对应的二进制并加入到本地
path 中。</li>
</ol>
<h3 id="本地快速部署">本地快速部署</h3>
<p>你可以使用 arkctl 工具快速地进行模块的构建和部署，提高本地调试和研发效率。</p>
<h4 id="场景-1模块-jar-包构建--部署到本地运行的基座中">场景 1：模块 jar 包构建 + 部署到本地运行的基座中。</h4>
<p>准备：</p>
<ol>
<li>在本地启动一个基座。</li>
<li>打开一个模块项目仓库。</li>
</ol>
<p>执行命令：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"># 需要在仓库的根目录下执行。</span>
</span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"># 比如，如果是 maven 项目，需要在根 pom.xml 所在的目录下执行。</span>
</span></span><span style="display:flex;"><span>arkctl deploy
</span></span></code></pre></div><p>命令执行完成后即部署成功，用户可以进行相关的模块功能调试验证。</p>
<h4 id="场景-2部署一个本地构建好的-jar-包到本地运行的基座中">场景 2：部署一个本地构建好的 jar 包到本地运行的基座中。</h4>
<p>准备：</p>
<ol>
<li>在本地启动一个基座。</li>
<li>准备一个构建好的 jar 包。</li>
</ol>
<p>执行命令：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span>arkctl deploy /path/to/your/pre/built/bundle-biz.jar
</span></span></code></pre></div><p>命令执行完成后即部署成功，用户可以进行相关的模块功能调试验证。</p>
<h4 id="场景-3-模块-jar-包构建--部署到远程运行的-k8s-基座中">场景 3: 模块 jar 包构建 + 部署到远程运行的 k8s 基座中。</h4>
<p>准备:</p>
<ol>
<li>在远程已经运行起来的基座 pod。</li>
<li>打开一个模块项目仓库。</li>
<li>本地需要有具备 exec 权限的 k8s 证书以及 kubectl 命令行工具。</li>
</ol>
<p>执行命令：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"># 需要在仓库的根目录下执行。</span>
</span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"># 比如，如果是 maven 项目，需要在根 pom.xml 所在的目录下执行。</span>
</span></span><span style="display:flex;"><span>arkctl deploy --pod <span style="color:#ce5c00;font-weight:bold">{</span>namespace<span style="color:#ce5c00;font-weight:bold">}</span>/<span style="color:#ce5c00;font-weight:bold">{</span>podName<span style="color:#ce5c00;font-weight:bold">}</span>
</span></span></code></pre></div><p>命令执行完成后即部署成功，用户可以进行相关的模块功能调试验证。</p>
<h4 id="场景-4-在多模块的-maven-项目中在-root-构建并部署子模块的-jar-包">场景 4: 在多模块的 Maven 项目中，在 Root 构建并部署子模块的 jar 包。</h4>
<p>准备：</p>
<ol>
<li>在本地启动一个基座。</li>
<li>打开一个多模块 Maven 项目仓库。</li>
</ol>
<p>执行命令：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"># 需要在仓库的根目录下执行。</span>
</span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"># 比如，如果是 maven 项目，需要在根 pom.xml 所在的目录下执行。</span>
</span></span><span style="display:flex;"><span>arkctl deploy --sub ./path/to/your/sub/module
</span></span></code></pre></div><p>命令执行完成后即部署成功，用户可以进行相关的模块功能调试验证。</p>
<h4 id="场景-5-查询当前基座中已经部署的模块">场景 5: 查询当前基座中已经部署的模块。</h4>
<p>准备：</p>
<ol>
<li>在本地启动一个基座。</li>
</ol>
<p>执行命令：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span>arkctl status
</span></span></code></pre></div><h4 id="场景-6-查询远程-k8s-环境基座中已经部署的模块">场景 6: 查询远程 k8s 环境基座中已经部署的模块。</h4>
<p>准备：</p>
<ol>
<li>在远程 k8s 环境启动一个基座。</li>
<li>确保本地有 kube 证书以及有关权限。</li>
</ol>
<p>执行命令：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span>arkctl status --pod <span style="color:#ce5c00;font-weight:bold">{</span>namespace<span style="color:#ce5c00;font-weight:bold">}</span>/<span style="color:#ce5c00;font-weight:bold">{</span>name<span style="color:#ce5c00;font-weight:bold">}</span>
</span></span></code></pre></div>
</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-28a800d400556ead949da2297e04f900">4.4.5 - 模块测试</h1>
    
	<h2 id="本地调试">本地调试</h2>
<p>您可以在本地或远程先启动基座，然后使用客户端 Arklet 暴露的 HTTP 接口在本地或远程部署模块，并且可以给模块代码打断点实现模块的本地或远程 Debug。<br />Arklet HTTP 接口主要提供了以下能力：</p>
<ol>
<li>部署和卸载模块。</li>
<li>查询所有已部署的模块信息。</li>
<li>查询各项系统和业务指标。</li>
</ol>
<h3 id="部署模块">部署模块</h3>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span>curl -X POST -H <span style="color:#4e9a06">&#34;Content-Type: application/json&#34;</span> http://127.0.0.1:1238/installBiz 
</span></span></code></pre></div><p>请求体样例：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;bizName&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;test&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;bizVersion&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;1.0.0&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#8f5902;font-style:italic">// local path should start with file://, alse support remote url which can be downloaded
</span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span>    <span style="color:#204a87;font-weight:bold">&#34;bizUrl&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;file:///Users/jaimezhang/workspace/github/sofa-ark-dynamic-guides/dynamic-provider/target/dynamic-provider-1.0.0-ark-biz.jar&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#000;font-weight:bold">}</span>
</span></span></code></pre></div><p>部署成功返回结果样例：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#204a87;font-weight:bold">&#34;code&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;SUCCESS&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>  <span style="color:#204a87;font-weight:bold">&#34;data&#34;</span><span style="color:#000;font-weight:bold">:{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;bizInfos&#34;</span><span style="color:#000;font-weight:bold">:[</span>
</span></span><span style="display:flex;"><span>      <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;bizName&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;dynamic-provider&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;bizState&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;ACTIVATED&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;bizVersion&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;1.0.0&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;declaredMode&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#204a87;font-weight:bold">true</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;identity&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;dynamic-provider:1.0.0&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;mainClass&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;io.sofastack.dynamic.provider.ProviderApplication&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;priority&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#0000cf;font-weight:bold">100</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;webContextPath&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;provider&#34;</span>
</span></span><span style="display:flex;"><span>      <span style="color:#000;font-weight:bold">}</span>
</span></span><span style="display:flex;"><span>    <span style="color:#000;font-weight:bold">],</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;code&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;SUCCESS&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;message&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;Install Biz: dynamic-provider:1.0.0 success, cost: 1092 ms, started at: 16:07:47,769&#34;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#000;font-weight:bold">}</span>
</span></span><span style="display:flex;"><span><span style="color:#000;font-weight:bold">}</span>
</span></span></code></pre></div><p>部署失败返回结果样例：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#204a87;font-weight:bold">&#34;code&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;FAILED&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>  <span style="color:#204a87;font-weight:bold">&#34;data&#34;</span><span style="color:#000;font-weight:bold">:{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;code&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;REPEAT_BIZ&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;message&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;Biz: dynamic-provider:1.0.0 has been installed or registered.&#34;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#000;font-weight:bold">}</span>
</span></span><span style="display:flex;"><span><span style="color:#000;font-weight:bold">}</span>
</span></span></code></pre></div><h3 id="卸载模块">卸载模块</h3>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span>curl -X POST -H <span style="color:#4e9a06">&#34;Content-Type: application/json&#34;</span> http://127.0.0.1:1238/uninstallBiz 
</span></span></code></pre></div><p>请求体样例：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;bizName&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;dynamic-provider&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;bizVersion&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;1.0.0&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#000;font-weight:bold">}</span>
</span></span></code></pre></div><p>卸载成功返回结果样例：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#204a87;font-weight:bold">&#34;code&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;SUCCESS&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#000;font-weight:bold">}</span>
</span></span></code></pre></div><p>卸载失败返回结果样例：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#204a87;font-weight:bold">&#34;code&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;FAILED&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>  <span style="color:#204a87;font-weight:bold">&#34;data&#34;</span><span style="color:#000;font-weight:bold">:{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;code&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;NOT_FOUND_BIZ&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;message&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;Uninstall biz: test:1.0.0 not found.&#34;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#000;font-weight:bold">}</span>
</span></span><span style="display:flex;"><span><span style="color:#000;font-weight:bold">}</span>
</span></span></code></pre></div><h3 id="查询模块">查询模块</h3>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span>curl -X POST -H <span style="color:#4e9a06">&#34;Content-Type: application/json&#34;</span> http://127.0.0.1:1238/queryAllBiz 
</span></span></code></pre></div><p>请求体样例：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{}</span>
</span></span></code></pre></div><p>返回结果样例：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#204a87;font-weight:bold">&#34;code&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;SUCCESS&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>  <span style="color:#204a87;font-weight:bold">&#34;data&#34;</span><span style="color:#000;font-weight:bold">:[</span>
</span></span><span style="display:flex;"><span>    <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&#34;bizName&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;dynamic-provider&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&#34;bizState&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;ACTIVATED&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&#34;bizVersion&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;1.0.0&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&#34;mainClass&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;io.sofastack.dynamic.provider.ProviderApplication&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&#34;webContextPath&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;provider&#34;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#000;font-weight:bold">},</span>
</span></span><span style="display:flex;"><span>    <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&#34;bizName&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;stock-mng&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&#34;bizState&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;ACTIVATED&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&#34;bizVersion&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;1.0.0&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&#34;mainClass&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;embed main&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&#34;webContextPath&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;/&#34;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#000;font-weight:bold">}</span>
</span></span><span style="display:flex;"><span>  <span style="color:#000;font-weight:bold">]</span>
</span></span><span style="display:flex;"><span><span style="color:#000;font-weight:bold">}</span>
</span></span></code></pre></div><h3 id="获取帮助">获取帮助</h3>
<p>Arklet 暴露的所有对外 HTTP 接口，可以查看 Arklet 接口帮助：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span>curl -X POST -H <span style="color:#4e9a06">&#34;Content-Type: application/json&#34;</span> http://127.0.0.1:1238/help 
</span></span></code></pre></div><p>请求体样例：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{}</span>
</span></span></code></pre></div><p>返回结果样例：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;code&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;SUCCESS&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;data&#34;</span><span style="color:#000;font-weight:bold">:[</span>
</span></span><span style="display:flex;"><span>        <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&#34;desc&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;query all ark biz(including master biz)&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&#34;id&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;queryAllBiz&#34;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#000;font-weight:bold">},</span>
</span></span><span style="display:flex;"><span>        <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&#34;desc&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;list all supported commands&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&#34;id&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;help&#34;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#000;font-weight:bold">},</span>
</span></span><span style="display:flex;"><span>        <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&#34;desc&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;uninstall one ark biz&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&#34;id&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;uninstallBiz&#34;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#000;font-weight:bold">},</span>
</span></span><span style="display:flex;"><span>        <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&#34;desc&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;switch one ark biz&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&#34;id&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;switchBiz&#34;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#000;font-weight:bold">},</span>
</span></span><span style="display:flex;"><span>        <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&#34;desc&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;install one ark biz&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&#34;id&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;installBiz&#34;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#000;font-weight:bold">}</span>
</span></span><span style="display:flex;"><span>    <span style="color:#000;font-weight:bold">]</span>
</span></span><span style="display:flex;"><span><span style="color:#000;font-weight:bold">}</span>
</span></span></code></pre></div><h2 id="本地构建如何不改变模块版本号">本地构建如何不改变模块版本号</h2>
<p>添加以下 maven profile，本地构建模块使用命令 mvn clean package -Plocal</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-xml" data-lang="xml"><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">&lt;profile&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;id&gt;</span>local<span style="color:#204a87;font-weight:bold">&lt;/id&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;build&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;plugins&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&lt;plugin&gt;</span>
</span></span><span style="display:flex;"><span>                <span style="color:#204a87;font-weight:bold">&lt;groupId&gt;</span>com.alipay.sofa<span style="color:#204a87;font-weight:bold">&lt;/groupId&gt;</span>
</span></span><span style="display:flex;"><span>                <span style="color:#204a87;font-weight:bold">&lt;artifactId&gt;</span>sofa-ark-maven-plugin<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
</span></span><span style="display:flex;"><span>                <span style="color:#204a87;font-weight:bold">&lt;configuration&gt;</span>
</span></span><span style="display:flex;"><span>                    <span style="color:#204a87;font-weight:bold">&lt;finalName&gt;</span>${project.artifactId}-${project.version}<span style="color:#204a87;font-weight:bold">&lt;/finalName&gt;</span>
</span></span><span style="display:flex;"><span>                    <span style="color:#204a87;font-weight:bold">&lt;bizVersion&gt;</span>${project.version}<span style="color:#204a87;font-weight:bold">&lt;/bizVersion&gt;</span>
</span></span><span style="display:flex;"><span>                <span style="color:#204a87;font-weight:bold">&lt;/configuration&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&lt;/plugin&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;/plugins&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;/build&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">&lt;/profile&gt;</span>
</span></span></code></pre></div><h2 id="单元测试">单元测试</h2>
<p>模块里支持使用标准 JUnit4 和 TestNG 编写和执行单元测试。</p>
<br/>
<br/>

</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-037484c6b7708a4128ecdd19d8578aaa">4.4.6 - 复用基座拦截器</h1>
    
	<h1 id="诉求">诉求</h1>
<p>基座中会定义很多 Aspect 切面（Spring 拦截器），你可能希望复用到模块中，但是模块和基座的 Spring 上下文是隔离的，就导致 Aspect 切面不会在模块中生效。<br/><br/></p>
<h1 id="解法">解法</h1>
<p>为原有的切面类创建一个代理对象，让模块能调用到这个代理对象，然后模块通过 AutoConfiguration 注解初始化出这个代理对象。完整步骤和示例代码如下：</p>
<h3 id="步骤-1">步骤 1：</h3>
<p>基座代码定义一个接口，定义切面的执行方法。这个接口需要对模块可见（在模块里引用相关依赖）：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">interface</span> <span style="color:#000">AnnotionService</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#000">Object</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">doAround</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">ProceedingJoinPoint</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">joinPoint</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">throws</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Throwable</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span></code></pre></div><h3 id="步骤-2">步骤 2：</h3>
<p>在基座中编写切面的具体实现，这个实现类需要加上 @SofaService 注解（SOFABoot）或者 @SpringService 注解（SpringBoot，<em>建设中</em>）：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#5c35cc;font-weight:bold">@Service</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#5c35cc;font-weight:bold">@SofaService</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">uniqueId</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;facadeAroundHandler&#34;</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">class</span> <span style="color:#000">FacadeAroundHandler</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">implements</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">AnnotionService</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">private</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">final</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">static</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Logger</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">LOG</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">LoggerConst</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">MY_LOGGER</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Object</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">doAround</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">ProceedingJoinPoint</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">joinPoint</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">throws</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Throwable</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">log</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">info</span><span style="color:#000;font-weight:bold">(</span><span style="color:#4e9a06">&#34;开始执行&#34;</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">joinPoint</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">proceed</span><span style="color:#000;font-weight:bold">();</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">log</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">info</span><span style="color:#000;font-weight:bold">(</span><span style="color:#4e9a06">&#34;执行完成&#34;</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span></code></pre></div><h3 id="步骤-3">步骤 3：</h3>
<p>在模块里使用 @Aspect 注解实现一个 Aspect，SOFABoot 通过 @SofaReference 注入基座上的 FacadeAroundHandler。<br /><strong>注意</strong>：这里不要声明成一个 Bean，不要加 @Component 或者 @Service 注解，主需要 @Aspect 注解。</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic">//注意，这里不必申明成一个bean，不要加@Component或者@Service</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#5c35cc;font-weight:bold">@Aspect</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">class</span> <span style="color:#000">FacadeAroundAspect</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#5c35cc;font-weight:bold">@SofaReference</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">uniqueId</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;facadeAroundHandler&#34;</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">private</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">AnnotionService</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">facadeAroundHandler</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#5c35cc;font-weight:bold">@Pointcut</span><span style="color:#000;font-weight:bold">(</span><span style="color:#4e9a06">&#34;@annotation(com.alipay.linglongmng.presentation.mvc.interceptor.FacadeAround)&#34;</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">void</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">facadeAroundPointcut</span><span style="color:#000;font-weight:bold">()</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#5c35cc;font-weight:bold">@Around</span><span style="color:#000;font-weight:bold">(</span><span style="color:#4e9a06">&#34;facadeAroundPointcut()&#34;</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Object</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">doAround</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">ProceedingJoinPoint</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">joinPoint</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">throws</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Throwable</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">return</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">facadeAroundHandler</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">doAround</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">joinPoint</span><span style="color:#000;font-weight:bold">);</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span></code></pre></div><h3 id="步骤-4">步骤 4：</h3>
<p>使用 @Configuration 注解写个 Configuration 配置类，把模块需要的 aspectj 对象都声明成 Spring Bean。<br /><strong>注意</strong>：这个 Configuration 类需要对模块可见，相关 Spring Jar 依赖需要以 <scope>provided</scope> 方式引进来。</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#5c35cc;font-weight:bold">@Configuration</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">class</span> <span style="color:#000">MngAspectConfiguration</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#5c35cc;font-weight:bold">@Bean</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">FacadeAroundAspect</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">facadeAroundAspect</span><span style="color:#000;font-weight:bold">()</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">return</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">new</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">FacadeAroundAspect</span><span style="color:#000;font-weight:bold">();</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#5c35cc;font-weight:bold">@Bean</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">EnvRouteAspect</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">envRouteAspect</span><span style="color:#000;font-weight:bold">()</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">return</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">new</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">EnvRouteAspect</span><span style="color:#000;font-weight:bold">();</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#5c35cc;font-weight:bold">@Bean</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">FacadeAroundAspect</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">facadeAroundAspect</span><span style="color:#000;font-weight:bold">()</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">return</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">new</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">FacadeAroundAspect</span><span style="color:#000;font-weight:bold">();</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span></code></pre></div><h3 id="步骤-5">步骤 5：</h3>
<p>模块代码中显示的依赖步骤 4 创建的 Configuration 配置类 MngAspectConfiguration。</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#5c35cc;font-weight:bold">@SpringBootApplication</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#5c35cc;font-weight:bold">@ImportResource</span><span style="color:#000;font-weight:bold">(</span><span style="color:#4e9a06">&#34;classpath*:META-INF/spring/*.xml&#34;</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#5c35cc;font-weight:bold">@ImportAutoConfiguration</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">value</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#000">MngAspectConfiguration</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">class</span><span style="color:#000;font-weight:bold">})</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">class</span> <span style="color:#000">ModuleBootstrapApplication</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">static</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">void</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">main</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">[]</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">args</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">SpringApplicationBuilder</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">builder</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">new</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">SpringApplicationBuilder</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">ModuleBootstrapApplication</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">class</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        	</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">web</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">WebApplicationType</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">NONE</span><span style="color:#000;font-weight:bold">);</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">builder</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">build</span><span style="color:#000;font-weight:bold">().</span><span style="color:#c4a000">run</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">args</span><span style="color:#000;font-weight:bold">);</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span></code></pre></div><br/>
<br/>

</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-06ace3863ce3b10117de52a241f0d9e0">4.4.7 - 复用基座数据源</h1>
    
	<h2 id="建议">建议</h2>
<p>强烈建议使用本文档方式，在模块中尽可能<strong>复用基座数据源</strong>，否则模块反复部署就会反复创建、消耗数据源连接，导致模块发布运维会变慢，同时也会额外消耗内存。<br/></p>
<h2 id="springboot-解法">SpringBoot 解法</h2>
<p>在模块的代码中写个 MybatisConfig 类即可，这样事务模板都是复用基座的，只有 Mybatis 的 SqlSessionFactoryBean 需要新创建。<br /> 参考 demo：/sofa-serverless/samples/springboot-samples/db/mybatis/biz1</p>
<p>通过<code>SpringBeanFinder.getBaseBean</code>获取到基座的 Bean 对象，然后注册成模块的 Bean：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#5c35cc;font-weight:bold">@Configuration</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#5c35cc;font-weight:bold">@MapperScan</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">basePackages</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;com.alipay.sofa.biz1.mapper&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">sqlSessionFactoryRef</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;mysqlSqlFactory&#34;</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#5c35cc;font-weight:bold">@EnableTransactionManagement</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">class</span> <span style="color:#000">MybatisConfig</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#8f5902;font-style:italic">//tips:不要初始化一个基座的DataSource，当模块被卸载的是，基座数据源会被销毁，transactionManager，transactionTemplate，mysqlSqlFactory被销毁没有问题</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#5c35cc;font-weight:bold">@Bean</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">name</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;transactionManager&#34;</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">PlatformTransactionManager</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">platformTransactionManager</span><span style="color:#000;font-weight:bold">()</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">return</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">PlatformTransactionManager</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">getBaseBean</span><span style="color:#000;font-weight:bold">(</span><span style="color:#4e9a06">&#34;transactionManager&#34;</span><span style="color:#000;font-weight:bold">);</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#5c35cc;font-weight:bold">@Bean</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">name</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;transactionTemplate&#34;</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">TransactionTemplate</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">transactionTemplate</span><span style="color:#000;font-weight:bold">()</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">return</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">TransactionTemplate</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">getBaseBean</span><span style="color:#000;font-weight:bold">(</span><span style="color:#4e9a06">&#34;transactionTemplate&#34;</span><span style="color:#000;font-weight:bold">);</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#5c35cc;font-weight:bold">@Bean</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">name</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;mysqlSqlFactory&#34;</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">SqlSessionFactoryBean</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">mysqlSqlFactory</span><span style="color:#000;font-weight:bold">()</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">throws</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">IOException</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#8f5902;font-style:italic">//数据源不能申明成模块spring上下文中的bean，因为模块卸载时会触发close方法</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">DataSource</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">dataSource</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">DataSource</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">getBaseBean</span><span style="color:#000;font-weight:bold">(</span><span style="color:#4e9a06">&#34;dataSource&#34;</span><span style="color:#000;font-weight:bold">);</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">SqlSessionFactoryBean</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">mysqlSqlFactory</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">new</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">SqlSessionFactoryBean</span><span style="color:#000;font-weight:bold">();</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">mysqlSqlFactory</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">setDataSource</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">dataSource</span><span style="color:#000;font-weight:bold">);</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">mysqlSqlFactory</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">setMapperLocations</span><span style="color:#000;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">new</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">PathMatchingResourcePatternResolver</span><span style="color:#000;font-weight:bold">()</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">                </span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">getResources</span><span style="color:#000;font-weight:bold">(</span><span style="color:#4e9a06">&#34;classpath:mappers/*.xml&#34;</span><span style="color:#000;font-weight:bold">));</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">return</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">mysqlSqlFactory</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span></code></pre></div><h2 id="sofaboot-解法">SOFABoot 解法</h2>
<p>如果 SOFABoot 基座没有开启多 bundle（Package 里没有 MANIFEST.MF 文件），则解法和上文 SpringBoot 完全一致。<br />如果有 MANIFEST.MF 文件，需要调用<code>BaseAppUtils.getBeanOfBundle</code>获取基座的 Bean，其中<strong>BASE_DAL_BUNDLE_NAME</strong> 为 MANIFEST.MF 里面的<code>Module-Name</code>：<br /><img src="https://intranetproxy.alipay.com/skylark/lark/0/2022/png/38696/1661758587977-7a499d0d-d5ca-4a68-9925-fa7258679d9b.png#clientId=ue6b6f4dc-5527-4&amp;errorMessage=unknown%20error&amp;from=paste&amp;height=458&amp;id=u531b3c3e&amp;originHeight=916&amp;originWidth=2042&amp;originalType=binary&amp;ratio=1&amp;rotation=0&amp;showTitle=false&amp;size=383535&amp;status=error&amp;style=none&amp;taskId=ua403e261-49af-4d10-99e6-12edf669677&amp;title=&amp;width=1021" alt="image.png"></p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#5c35cc;font-weight:bold">@Configuration</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#5c35cc;font-weight:bold">@MapperScan</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">basePackages</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;com.alipay.serverless.dal.dao&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">sqlSessionFactoryRef</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;mysqlSqlFactory&#34;</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#5c35cc;font-weight:bold">@EnableTransactionManagement</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">class</span> <span style="color:#000">MybatisConfig</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#8f5902;font-style:italic">// 注意：不要初始化一个基座的 DataSource，会导致模块被热卸载的时候，基座的数据源被销毁，不符合预期。</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#8f5902;font-style:italic">// 但是 transactionManager，transactionTemplate，mysqlSqlFactory 这些资源被销毁没有问题</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">private</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">static</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">final</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">String</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">BASE_DAL_BUNDLE_NAME</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;com.alipay.serverless.dal&#34;</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#5c35cc;font-weight:bold">@Bean</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">name</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;transactionManager&#34;</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">PlatformTransactionManager</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">platformTransactionManager</span><span style="color:#000;font-weight:bold">()</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">return</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">PlatformTransactionManager</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">BaseAppUtils</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">getBeanOfBundle</span><span style="color:#000;font-weight:bold">(</span><span style="color:#4e9a06">&#34;transactionManager&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#000">BASE_DAL_BUNDLE_NAME</span><span style="color:#000;font-weight:bold">);</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#5c35cc;font-weight:bold">@Bean</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">name</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;transactionTemplate&#34;</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">TransactionTemplate</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">transactionTemplate</span><span style="color:#000;font-weight:bold">()</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">return</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">TransactionTemplate</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">BaseAppUtils</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">getBeanOfBundle</span><span style="color:#000;font-weight:bold">(</span><span style="color:#4e9a06">&#34;transactionTemplate&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#000">BASE_DAL_BUNDLE_NAME</span><span style="color:#000;font-weight:bold">);</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#5c35cc;font-weight:bold">@Bean</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">name</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;mysqlSqlFactory&#34;</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">SqlSessionFactoryBean</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">mysqlSqlFactory</span><span style="color:#000;font-weight:bold">()</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">throws</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">IOException</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#8f5902;font-style:italic">//数据源不能申明成模块spring上下文中的bean，因为模块卸载时会触发close方法</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">ZdalDataSource</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">dataSource</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">ZdalDataSource</span><span style="color:#000;font-weight:bold">)</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">BaseAppUtils</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">getBeanOfBundle</span><span style="color:#000;font-weight:bold">(</span><span style="color:#4e9a06">&#34;dataSource&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#000">BASE_DAL_BUNDLE_NAME</span><span style="color:#000;font-weight:bold">);</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">SqlSessionFactoryBean</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">mysqlSqlFactory</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">new</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">SqlSessionFactoryBean</span><span style="color:#000;font-weight:bold">();</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">mysqlSqlFactory</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">setDataSource</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">dataSource</span><span style="color:#000;font-weight:bold">);</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">mysqlSqlFactory</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">setMapperLocations</span><span style="color:#000;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">new</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">PathMatchingResourcePatternResolver</span><span style="color:#000;font-weight:bold">()</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">                </span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">getResources</span><span style="color:#000;font-weight:bold">(</span><span style="color:#4e9a06">&#34;classpath:mapper/*.xml&#34;</span><span style="color:#000;font-weight:bold">));</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">return</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">mysqlSqlFactory</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span></code></pre></div><br/>
<br/>

</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-4a763f2560193bc6f6a4c64874383f22">4.4.8 - 静态合并部署</h1>
    
	<h2 id="介绍">介绍</h2>
<p>SOFAArk 提供了静态合并部署能力，在开发阶段，应用可以将其他应用构建成的 <strong>Biz 包（模块应用)</strong>，并被最终的 <strong>Base 包（基座应用）</strong> 加载。
用户可以把 Biz 包统一放置在某个目录中，然后通过启动参数告知基座扫描这个目录，以此完成静态合并部署（详情见下描述）。如此，开发不需要考虑相互之间依赖冲突问题，Biz 之间则通过 @SofaService 和 @SofaReference 发布/引用 JVM 服务（<em>SOFABoot，SpringBoot 还在建设中</em>
）进行交互。</p>
<h2 id="步骤-1模块应用打包成-ark-biz">步骤 1：模块应用打包成 Ark Biz</h2>
<p>如果开发者希望自己应用的 Ark Biz 包能够被其他应用直接当成 Jar 包依赖，进而运行在同一个 SOFAArk 容器之上，那么就需要打包发布 Ark Biz
包，详见 <a href="https://www.sofastack.tech/projects/sofa-boot/sofa-ark-ark-biz/">Ark Biz 介绍</a>。 Ark Biz 包使用
Maven 插件 sofa-ark-maven-plugin 打包生成。</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-xml" data-lang="xml"><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">&lt;build&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;plugin&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;groupId&gt;</span>com.alipay.sofa<span style="color:#204a87;font-weight:bold">&lt;/groupId&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;artifactId&gt;</span>sofa-ark-maven-plugin<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;version&gt;</span>${sofa.ark.version}<span style="color:#204a87;font-weight:bold">&lt;/version&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;executions&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&lt;execution&gt;</span>
</span></span><span style="display:flex;"><span>                <span style="color:#204a87;font-weight:bold">&lt;id&gt;</span>default-cli<span style="color:#204a87;font-weight:bold">&lt;/id&gt;</span>
</span></span><span style="display:flex;"><span>                <span style="color:#204a87;font-weight:bold">&lt;goals&gt;</span>
</span></span><span style="display:flex;"><span>                    <span style="color:#204a87;font-weight:bold">&lt;goal&gt;</span>repackage<span style="color:#204a87;font-weight:bold">&lt;/goal&gt;</span>
</span></span><span style="display:flex;"><span>                <span style="color:#204a87;font-weight:bold">&lt;/goals&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&lt;/execution&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;/executions&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;/plugin&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">&lt;/build&gt;</span>
</span></span></code></pre></div><h2 id="步骤-2将上述-jar-包移动到指定目录">步骤 2：将上述 jar 包移动到指定目录。</h2>
<p>把需要部署的 biz jar 都移动到指定目录，如：/home/sofa-ark/biz/</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span>mv /path/to/your/biz/jar /home/sofa-ark/biz/
</span></span></code></pre></div><h2 id="步骤-3启动基座并通过--d-参指定-biz-目录">步骤 3：启动基座，并通过 -D 参指定 biz 目录</h2>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span>java -jar -Dcom.alipay.sofa.ark.static.biz.dir<span style="color:#ce5c00;font-weight:bold">=</span>/home/sofa-ark/biz/ sofa-ark-base.jar
</span></span></code></pre></div><h2 id="步骤-4验证-ark-biz模块启动">步骤 4：验证 Ark Biz（模块）启动</h2>
<p>在基座启动成功后，可以通过 telnet 启动 SOFAArk 客户端交互界面：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span>telnet localhost <span style="color:#0000cf;font-weight:bold">1234</span>
</span></span></code></pre></div><p>然后执行如下命令查看模块列表：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span>biz -a
</span></span></code></pre></div><p>此时应当可以看到 Master Biz（基座）和所有静态合并部署的 Ark Biz（模块）。<br/>
上述操作可以通过 <a href="https://github.com/sofastack/sofa-serverless/blob/master/samples/springboot-samples/web/tomcat/README.md#%E5%AE%9E%E9%AA%8C%E5%86%85%E5%AE%B9(%E9%9D%99%E6%80%81%E5%90%88%E5%B9%B6%E9%83%A8%E7%BD%B2)">SOFAArk 静态合并部署样例</a>
体验。<br/></p>
<br/>
<br/>

</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-dbe415e386e1bcdf1f3e7a62a91e6eb6">4.4.9 - 模块中官方支持的中间件客户端</h1>
    
	<p>在 SOFAServerless 模块中，官方目前支持并兼容常见的中间件客户端。<br /><strong>注意</strong>，这里 “<strong>已经支持</strong>” 需要在基座 POM
中引入相关客户端依赖（<strong>强烈建议使用 SpringBoot Starter 方式引入相关依赖</strong>），同时在模块 POM 中也引入相关依赖并设置 *
<em><scope>provided</scope></em>* 将依赖委托给基座加载。</p>
<br/>
<table>
<thead>
<tr>
<th>中间件客户端</th>
<th>版本号</th>
<th>备注</th>
</tr>
</thead>
<tbody>
<tr>
<td>JDK</td>
<td>8.x<br />17.x</td>
<td><em><strong>已经支持</strong></em><br /></td>
</tr>
<tr>
<td>SpringBoot</td>
<td>&gt;= 2.3.0  或  3.x</td>
<td><em><strong>已经支持</strong></em><br />JDK17 + SpringBoot3.x 基座和模块完整使用样例可<a href="https://github.com/sofastack/sofa-serverless/tree/master/samples/springboot3-samples/web/tomcat">参见此处</a></td>
</tr>
<tr>
<td>SpringBoot Cloud</td>
<td>&gt;= 2.7.x</td>
<td><em><strong>已经支持</strong></em><br/> 基座和模块完整使用样例可<a href="https://github.com/sofastack/sofa-serverless/tree/master/samples/springboot-samples/springcloud/">参见此处</a></td>
</tr>
<tr>
<td>SOFABoot</td>
<td>&gt;= 3.9.0  或  4.x</td>
<td><em><strong>已经支持</strong></em><br /></td>
</tr>
<tr>
<td>JMX</td>
<td>N/A</td>
<td><em><strong>已经支持</strong></em><br /> 需要给基座加  <em>-Dspring.jmx.default-domain=${spring.application.name}</em>  启动参数 <br /></td>
</tr>
<tr>
<td>log4j2</td>
<td>任意</td>
<td><em><strong>已经支持</strong></em>。在基座和模块引入 log4j2，并额外引入依赖：<br/>&lt;dependency&gt;<br/>  &lt;groupId&gt;com.alipay.sofa.serverless&lt;/groupId&gt;<br/>  &lt;artifactId&gt;sofa-serverless-adapter-log4j2&lt;/artifactId&gt;<br/>  &lt;version&gt;${最新版 SOFAServerless 版本}&lt;/version&gt;<br/>  &lt;scope&gt;provided&lt;/scope&gt; &lt;!&ndash; 模块需要 provided &ndash;&gt;<br/>  &lt;/dependency&gt;<br/>基座和模块完整使用样例<a href="https://github.com/sofastack/sofa-serverless/blob/master/samples/springboot-samples/logging/README.md">参见此处</a></td>
</tr>
<tr>
<td>slf4j-api</td>
<td>1.x 且 &gt;= 1.7</td>
<td><em><strong>已经支持</strong></em><br /></td>
</tr>
<tr>
<td>tomcat</td>
<td>7.x、8.x、9.x、10.x <br />及以上均可</td>
<td><em><strong>已经支持</strong></em><br /> 基座和模块完整使用样例可<a href="https://github.com/sofastack/sofa-serverless/blob/master/samples/springboot-samples/web/tomcat">参见此处</a></td>
</tr>
<tr>
<td>netty</td>
<td>4.x</td>
<td><em><strong>已经支持</strong></em><br /> 基座和模块完整使用样例可<a href="https://github.com/sofastack/sofa-serverless/blob/master/samples/springboot-samples/web/webflux">参见此处</a></td>
</tr>
<tr>
<td>sofarpc</td>
<td>&gt;= 5.8.6</td>
<td><em><strong>已经支持</strong></em><br /></td>
</tr>
<tr>
<td>dubbo</td>
<td>3.x</td>
<td><em><strong>已经支持</strong></em><br/>基座和模块完整使用样例及注意事项可<a href="https://github.com/sofastack/sofa-serverless/blob/master/samples/dubbo-samples/rpc/grpc">参见此处</a></td>
</tr>
<tr>
<td>grpc</td>
<td>1.x 且 &gt;= 1.42</td>
<td><em><strong>已经支持</strong></em><br/>基座和模块完整使用样例及注意事项可<a href="https://github.com/sofastack/sofa-serverless/blob/master/samples/dubbo-samples/rpc/grpc">参见此处</a></td>
</tr>
<tr>
<td>protobuf-java</td>
<td>3.x 且 &gt;= 3.17</td>
<td><em><strong>已经支持</strong></em><br/>基座和模块完整使用样例及注意事项可<a href="https://github.com/sofastack/sofa-serverless/blob/master/samples/dubbo-samples/rpc/grpc">参见此处</a></td>
</tr>
<tr>
<td>apollo</td>
<td>1.x 且 &gt;= 1.6.0</td>
<td><em><strong>已经支持</strong></em><br/>基座和模块完整使用样例及注意事项可<a href="https://github.com/sofastack/sofa-serverless/blob/master/samples/springboot-samples/config/apollo">参见此处</a></td>
</tr>
<tr>
<td>nacos</td>
<td>2.1.x</td>
<td><em><strong>已经支持</strong></em><br/>     基座和模块完整使用样例及注意事项可<a href="https://github.com/sofastack/sofa-serverless/blob/master/samples/springboot-samples/config/nacos">参见此处</a></td>
</tr>
<tr>
<td>kafka-client</td>
<td>&gt;= 2.8.0  或<br />&gt;= 3.4.0</td>
<td><em><strong>已经支持</strong></em><br />基座和模块完整使用样例可<a href="https://github.com/sofastack/sofa-serverless/blob/master/samples/springboot-samples/logging/README.md">参见此处</a></td>
</tr>
<tr>
<td>rocketmq</td>
<td>4.x 且 &gt;= 4.3.0</td>
<td><em><strong>已经支持</strong></em> <br/>基座和模块完整使用样例可<a href="https://github.com/sofastack/sofa-serverless/blob/master/samples/springboot-samples/msg/rocketmq/README.md">参见此处</a></td>
</tr>
<tr>
<td>jedis</td>
<td>3.x</td>
<td><em><strong>已经支持</strong></em><br />基座和模块完整使用样例可<a href="https://github.com/sofastack/sofa-serverless/tree/master/samples/springboot-samples/redis">参见此处</a></td>
</tr>
<tr>
<td>xxl-job</td>
<td>2.x 且 &gt;= 2.1.0</td>
<td><em><strong>已经支持</strong></em><br />需要在模块里声明为 compile 依赖独立使用 <br/></td>
</tr>
<tr>
<td>mybatis</td>
<td>&gt;= 2.2.2  或<br />&gt;= 3.5.12</td>
<td><em><strong>已经支持</strong></em><br />基座和模块完整使用样例可<a href="https://github.com/sofastack/sofa-serverless/blob/master/samples/springboot-samples/db/mybatis/README.md">参见此处</a></td>
</tr>
<tr>
<td>druid</td>
<td>1.x</td>
<td><em><strong>已经支持</strong></em><br />基座和模块完整使用样例可<a href="https://github.com/sofastack/sofa-serverless/blob/master/samples/springboot-samples/db/mybatis/README.md">参见此处</a></td>
</tr>
<tr>
<td>mysql-connector-java</td>
<td>8.x</td>
<td><em><strong>已经支持</strong></em><br />基座和模块完整使用样例可<a href="https://github.com/sofastack/sofa-serverless/blob/master/samples/springboot-samples/db/mybatis/README.md">参见此处</a></td>
</tr>
<tr>
<td>postgresql</td>
<td>42.x 且 &gt;= 42.3.8</td>
<td><em><strong>已经支持</strong></em></td>
</tr>
<tr>
<td>mongodb</td>
<td>4.6.1</td>
<td><em><strong>已经支持</strong></em> <br/>     基座和模块完整使用样例可<a href="https://github.com/sofastack/sofa-serverless/blob/master/samples/springboot-samples/db/mongo/README.md">参见此处</a></td>
</tr>
<tr>
<td>hibernate</td>
<td>5.x 且 &gt;= 5.6.15</td>
<td><em><strong>已经支持</strong></em></td>
</tr>
<tr>
<td>j2cache</td>
<td>任意</td>
<td><em><strong>已经支持</strong></em><br />需要在模块里声明为 compile 依赖独立使用 <br/></td>
</tr>
<tr>
<td>opentracing</td>
<td>0.x 且 &gt;= 0.32.0</td>
<td><em><strong>已经支持</strong></em></td>
</tr>
<tr>
<td>elasticsearch</td>
<td>7.x 且 &gt;= 7.6.2</td>
<td><em><strong>已经支持</strong></em></td>
</tr>
<tr>
<td>jaspyt</td>
<td>1.x 且 &gt;= 1.9.3</td>
<td><em><strong>已经支持</strong></em></td>
</tr>
<tr>
<td>OKHttp</td>
<td>-</td>
<td><em><strong>已经支持</strong></em><br/>需要放在基座里，请使用<a href="https://github.com/sofastack/sofa-serverless/blob/master/docs/content/zh-cn/docs/tutorials/module-development/module-slimming.md">模块自动瘦身能力</a></td>
</tr>
<tr>
<td>io.kubernetes:client</td>
<td>10.x 且 &gt;= 10.0.0</td>
<td><em><strong>已经支持</strong></em></td>
</tr>
<tr>
<td>net.java.dev.jna</td>
<td>5.x 且 &gt;= 5.12.1</td>
<td><em><strong>已经支持</strong></em></td>
</tr>
<tr>
<td>prometheus</td>
<td>-</td>
<td>待验证支持</td>
</tr>
</tbody>
</table>

</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-4c134980130d1dc3c830b9224a754361">4.4.10 - SOFAArk 关键用户文档</h1>
    
	<p><b><a href="https://www.sofastack.tech/projects/sofa-boot/sofa-ark-biz-lifecycle/">模块生命周期</a></b><br /><br />
<b><a href="https://www.sofastack.tech/projects/sofa-boot/sofa-ark-ark-event/">Ark 事件机制</a></b><br /><br />
<b><a href="https://www.sofastack.tech/projects/sofa-boot/sofa-ark-ark-log/">Ark 自身日志</a></b><br /><br /></p>
<br/>
<br/>

</div>



    
	
  

    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-307f45cbc34bd56c2422e01b460303bb">4.5 - 模块运维</h1>
    
	
</div>



    
      
  
  
  
  

  
  

  
    
    
	
    

<div class="td-content" style="">
    
	<h1 id="pg-f274515d3bf16798aa419325f53c707a">4.5.1 - 模块上线与下线</h1>
    
	<h2 id="模块上线">模块上线</h2>
<p>在 K8S 集群中创建一个 ModuleDeployment CR 资源即可完成模块上线，例如：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>kubectl apply -f sofa-serverless/module-controller/config/samples/module-deployment_v1alpha1_moduledeployment.yaml --namespace yournamespace
</span></span></code></pre></div><p>其中 <em>deployment_v1alpha1_moduledeployment.yaml</em> 替换成您的 ModuleDeployment 定义 yaml 文件，<em>yournamespace</em> 替换成您的 namespace。module-deployment_v1alpha1_moduledeployment.yaml 完整内容如下：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">apiVersion</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">serverless.alipay.com/v1alpha1</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">kind</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">ModuleDeployment</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">metadata</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">labels</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">app.kubernetes.io/name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">moduledeployment</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">app.kubernetes.io/instance</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">moduledeployment-sample</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">app.kubernetes.io/part-of</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">module-controller</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">app.kubernetes.io/managed-by</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">kustomize</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">app.kubernetes.io/created-by</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">module-controller</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">moduledeployment-sample</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">spec</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">baseDeploymentName</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">dynamic-stock-deployment</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">template</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">spec</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">      </span><span style="color:#204a87;font-weight:bold">module</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">provider</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">version</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#39;1.0.2&#39;</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">url</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">http://serverless-opensource.oss-cn-shanghai.aliyuncs.com/module-packages/stable/dynamic-provider-1.0.2-ark-biz.jar</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">replicas</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">2</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">operationStrategy</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#8f5902;font-style:italic"># 此处可自定义发布运维策略</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">upgradePolicy</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">installThenUninstall</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">needConfirm</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">true</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">useBeta</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">false</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">batchCount</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">2</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">schedulingStrategy</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#8f5902;font-style:italic"># 此处可自定义调度策略</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">schedulingPolicy</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Scatter</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span></code></pre></div><p>ModuleDeployment 所有字段可参考 <a href="/docs/contribution-guidelines/module-controller/crd-definition">ModuleDeployment CRD 字段解释</a>。<br />如果要自定义模块发布运维策略（比如分组、Beta、暂停等）可配置 operationStrategy 和 schedulingStrategy，具体可参考<a href="../operation-and-scheduling-strategy">模块发布运维策略</a>。<br />样例演示的是使用 kubectl 方式，直接调用 K8S APIServer 创建 ModuleDeployment CR 一样能实现模块分组上线。</p>
<h2 id="模块下线">模块下线</h2>
<p>在 K8S 集群中删除一个 ModuleDeployment CR 资源即可完成模块下线，例如：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>kubectl delete yourmoduledeployment --namespace yournamespace
</span></span></code></pre></div><p>其中 <em>yourmoduledeployment</em> 替换成您的 ModuleDeployment 名字（ModuleDeployment 的 metadata name），<em>yournamespace</em> 替换成您的 namespace。<br />如果要自定义模块发布运维策略（比如分组、Beta、暂停等）可配置 operationStrategy 和 schedulingStrategy，具体可参考<a href="../operation-and-scheduling-strategy">模块发布运维策略</a>。<br />样例演示的是使用 kubectl 方式，直接调用 K8S APIServer 删除 ModuleDeployment CR 一样能实现模块分组下线。</p>
<br/>
<br/>

</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-7b5bd50a9b9adfe3d8e27a3a4117e738">4.5.2 - 模块发布</h1>
    
	<h2 id="模块发布">模块发布</h2>
<p>修改 ModuleDeployment.spec.template.spec.module.version 字段和 ModuleDeployment.spec.template.spec.module.url（可选）字段并重新 apply，即可实现新版本模块的分组发布，例如：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>kubectl apply -f sofa-serverless/module-controller/config/samples/module-deployment_v1alpha1_moduledeployment.yaml --namespace yournamespace
</span></span></code></pre></div><p>其中 <em>deployment_v1alpha1_moduledeployment.yaml</em> 替换成您的 ModuleDeployment 定义 yaml 文件，<em>yournamespace</em> 替换成您的 namespace。module-deployment_v1alpha1_moduledeployment.yaml 完整内容如下：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">apiVersion</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">serverless.alipay.com/v1alpha1</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">kind</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">ModuleDeployment</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">metadata</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">labels</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">app.kubernetes.io/name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">moduledeployment</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">app.kubernetes.io/instance</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">moduledeployment-sample</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">app.kubernetes.io/part-of</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">module-controller</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">app.kubernetes.io/managed-by</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">kustomize</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">app.kubernetes.io/created-by</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">module-controller</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">moduledeployment-sample</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">spec</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">baseDeploymentName</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">dynamic-stock-deployment</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">template</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">spec</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">      </span><span style="color:#204a87;font-weight:bold">module</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">provider</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">version</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#39;2.0.0&#39;</span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#8f5902;font-style:italic"># 注意：这里将 version 字段从 1.0.2 修改为了 2.0.0 即可实现模块新版本分组发布</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#8f5902;font-style:italic"># 注意：url 字段可以修改为新的 jar 包地址，也可以不用修改</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">url</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">http://serverless-opensource.oss-cn-shanghai.aliyuncs.com/module-packages/stable/dynamic-provider-1.0.2-ark-biz.jar</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">replicas</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">2</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">operationStrategy</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">upgradePolicy</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">install_then_uninstall</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">needConfirm</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">true</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">grayTimeBetweenBatchSeconds</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">useBeta</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">false</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">batchCount</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">2</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">schedulingStrategy</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">schedulingPolicy</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">scatter</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span></code></pre></div><p>如果要自定义模块发布运维策略可配置 operationStrategy，具体可参考<a href="/docs/contribution-guidelines/module-controller/crd-definition">模块发布运维策略</a>。<br />样例演示的是使用 kubectl 方式，直接调用 K8S APIServer 修改 ModuleDeployment CR 一样能实现分组发布。</p>
<h2 id="模块回滚">模块回滚</h2>
<p>重新修改 ModuleDeployment.spec.template.spec.module.version 字段和 ModuleDeployment.spec.template.spec.module.url（可选）字段并重新 apply，即可实现模块的分组回滚发布。</p>
<br/>
<br/>

</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-03f7fcbe7eb355b82c98153891be1e48">4.5.3 - 基座和模块不兼容发布</h1>
    
	<h2 id="步骤--1">步骤  1</h2>
<p>修改基座代码和模块代码，然后将基座构建为新版本的镜像，将模块构建为新版本的代码包（Java 就是 Jar 包）。</p>
<h2 id="步骤--2">步骤  2</h2>
<p>修改模块对应的 ModuleDeployment.spec.template.spec.module.url 为新的模块代码包地址。</p>
<h2 id="步骤--3">步骤  3</h2>
<p>使用 K8S Deployment 发布基座到新版本镜像（会触发基座容器的替换或重启），基座容器启动时会拉取 ModuleDeployment 上最新的模块代码包地址，从而实现了基座与模块的不兼容变更（即同时发布）。<br/></p>
<br/>
<br/>

</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-ac1464ebc2e0083dd90ccb0c00118fca">4.5.4 - 模块扩缩容与替换</h1>
    
	<h2 id="模块扩缩容">模块扩缩容</h2>
<p>修改 ModuleDeployment CR 的 replicas 字段并重新 apply，即可实现模块扩缩容，例如：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>kubectl apply -f sofa-serverless/module-controller/config/samples/module-deployment_v1alpha1_moduledeployment.yaml --namespace yournamespace
</span></span></code></pre></div><p>其中 <em>deployment_v1alpha1_moduledeployment.yaml</em> 替换成您的 ModuleDeployment 定义 yaml 文件，<em>yournamespace</em> 替换成您的 namespace。module-deployment_v1alpha1_moduledeployment.yaml 完整内容如下：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">apiVersion</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">serverless.alipay.com/v1alpha1</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">kind</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">ModuleDeployment</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">metadata</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">labels</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">app.kubernetes.io/name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">moduledeployment</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">app.kubernetes.io/instance</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">moduledeployment-sample</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">app.kubernetes.io/part-of</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">module-controller</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">app.kubernetes.io/managed-by</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">kustomize</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">app.kubernetes.io/created-by</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">module-controller</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">moduledeployment-sample</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">spec</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">baseDeploymentName</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">dynamic-stock-deployment</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">template</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">spec</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">      </span><span style="color:#204a87;font-weight:bold">module</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">provider</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">version</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#39;1.0.2&#39;</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">url</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">http://serverless-opensource.oss-cn-shanghai.aliyuncs.com/module-packages/stable/dynamic-provider-1.0.2-ark-biz.jar</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">replicas</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">2</span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#8f5902;font-style:italic"># 注意：在此处修改模块实例 Module 副本数，实现扩缩容</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">operationStrategy</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">upgradePolicy</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">installThenUninstall</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">needConfirm</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">true</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">useBeta</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">false</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">batchCount</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">2</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">schedulingStrategy</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#8f5902;font-style:italic"># 此处可自定义调度策略</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">schedulingPolicy</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Scatter  </span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span></code></pre></div><p>如果要自定义模块发布运维策略可配置 operationStrategy 和 schedulingStrategy，具体可参考<a href="../operation-and-scheduling-strategy">模块发布运维策略</a>。<br />样例演示的是使用 kubectl 方式，直接调用 K8S APIServer 修改 ModuleDeployment CR 一样能实现扩缩容。</p>
<h2 id="模块替换">模块替换</h2>
<p>在 K8S 集群中删除一个 Module CR 资源即可完成模块替换，例如：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>kubectl delete yourmodule --namespace yournamespace
</span></span></code></pre></div><p>其中 <em>yourmodule</em> 替换成您的 Module CR 实体名字（Module 的 metadata name），<em>yournamespace</em> 替换成您的 namespace。<br />样例演示的是使用 kubectl 方式，直接调用 K8S APIServer 删除 Module CR 一样能实现模块替换。</p>
<br/>
<br/>

</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-7011e375d7565bd7cea7f9347f8e8c9e">4.5.5 - 模块发布运维策略</h1>
    
	<h2 id="运维策略">运维策略</h2>
<p>为了实现生产环境的无损变更，模块发布运维提供了安全可靠的变更能力，用户可以在 ModuleDeployment CR spec 的 operationStrategy 中，配置发布运维的变更策略。operationStrategy 内具体字段解释如下：</p>
<table>
<thead>
<tr>
<th>字段名</th>
<th>字段解释</th>
<th>取值范围</th>
<th>取值解释</th>
</tr>
</thead>
<tbody>
<tr>
<td>batchCount</td>
<td>分批发布运维批次数</td>
<td>1 - N</td>
<td>分 1 - N 批次发布运维模块</td>
</tr>
<tr>
<td>useBeta</td>
<td>是否启用 beta 分组发布。启用 beta 分组发布会让第一批次只有一个 IP 做灰度，剩下的 IP 再划分成 (batchCount - 1) 批</td>
<td>true 或 false</td>
<td>true 表示启用 beta 分组<br />false 表示不启用 beta 分组</td>
</tr>
<tr>
<td>needConfirm</td>
<td>是否启用分组确认。启用后每一批次模块发布运维后，都会暂停，修改 ModuleDeployment.spec.pause 字段为 <strong>false</strong> 后，则运维继续</td>
<td>true 或 false</td>
<td>true 表示启用分组确认<br />false 表示不启用分组确认</td>
</tr>
<tr>
<td>grayTime</td>
<td>每一个发布运维批次完成后，sleep 多少时间才能继续执行下一个批次</td>
<td>0 - N</td>
<td>批次间的灰度时长，单位秒，0 表示批次完成后立即执行下一批次，N 表示批次完成后 sleep N 秒再执行下一批次</td>
</tr>
</tbody>
</table>
<h2 id="调度策略">调度策略</h2>
<p>可以为基座 K8S Pod Deployment 配置 Label &ldquo;serverless.alipay.com/max-module-count&rdquo;，指定每个 Pod 最多可以安装多少个模块。支持配置为 0 - N 的整数。模块支持打散调度和堆叠调度。<br />
<strong>打散调度</strong>：设置 ModuleDeployment.spec.schedulingStrategy.schedulingPolicy 为 <strong>scatter</strong>。打散调度表示在模块上线、扩容、替换时，优先把模块调度到模块数最少的机器上去安装。<br />
<strong>堆叠调度</strong>：设置 ModuleDeployment.spec.schedulingStrategy.schedulingPolicy 为 <strong>stacking</strong>。堆叠调度表示在模块上线、扩容、替换时，优先把模块调度到模块数最多且没达到基座 max-module-count 上限的机器上去安装。</p>
<h2 id="保护机制">保护机制</h2>
<p><em>(正在开发中，10.15 上线)</em> 您可以配置 ModuleDeployment.spec.maxUnavailable 指定模块在发布运维过程中，最多有几个模块副本可以同时处在不可用状态。模块发布运维需要更新 K8S Service 并卸载模块，会导致该模块副本不可用。<strong>配置为 50%</strong> 表示模块发布运维的一个批次，必须保证<strong>至少 50% 的模块副本可用</strong>，否则 ModuleDeployment.status 会展示报错信息。</p>
<h2 id="对等和非对等">对等和非对等</h2>
<p>您可以配置 ModuleDeployment.spec.replicas 指定模块采用对等还是非对等部署架构。<br />
<strong>非对等架构</strong>：设置 ModuleDeployment.spec.replicas 为 **0 - N **表示非对等架构。非对等架构下必须要为 ModuleDeployment、ModueRepicaSet 设置副本数，因此非对等架构下支持模块的扩容和缩容操作。<br />
<strong>对等架构</strong>：设置 ModuleDeployment.spec.replicas 为 **-1 <strong>表示对等架构</strong>。**对等架构下，K8S Pod Deployment 有多少副本数模块就自动安装到多少个 Pod，模块的副本数始终与 K8S Pod Deployment 副本数一致。因此对等架构下不支持模块的扩缩容操作。<em>对等架构正在建设中，预计 10.30 发布。</em></p>
<br/>
<br/>

</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-24eb3a9c0234e21473eec787d4ae6d7a">4.5.6 - 独立使用 Arklet</h1>
    
	<p>Arklet 作为 SOFAServerless 模块发布运维的 Agent（定位类似 K8S 的 Kubelet），可以完全脱离 ModuleController 独立使用。它暴露了一组安装卸载模块的 HTTP 接口，从而可以让 SOFAServerless 对接到您自己的发布运维平台，<a href="https://github.com/sofastack/sofa-serverless/blob/feature.arklet_v1/arklet/README.md">接口文档详见此处</a>。</p>
<br/>
<br/>

</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-c588ae48a684af6c4c57ee4d9aae6ce4">4.5.7 - 模块信息查看</h1>
    
	<h4 id="查看某个基座上所有安装的模块名称和状态">查看某个基座上所有安装的模块名称和状态</h4>
<pre tabindex="0"><code>kubectl get module -n &lt;namespace&gt; -l serverless.alipay.com/base-instance-ip=&lt;pod-ip&gt; -o custom-columns=NAME:.metadata.name,STATUS:.status.status
</code></pre><p>或</p>
<pre tabindex="0"><code>kubectl get module -n &lt;namespace&gt; -l serverless.alipay.com/base-instance-name=&lt;pod-name&gt; -o custom-columns=NAME:.metadata.name,STATUS:.status.status
</code></pre><h4 id="查看某个基座上所有安装的模块详细信息">查看某个基座上所有安装的模块详细信息</h4>
<pre tabindex="0"><code>kubectl describe module -n &lt;namespace&gt; -l serverless.alipay.com/base-instance-ip=&lt;pod-ip&gt;
</code></pre><p>或</p>
<pre tabindex="0"><code>kubectl describe module -n &lt;namespace&gt; -l serverless.alipay.com/base-instance-name=&lt;pod-name&gt;
</code></pre><p>替换<code>&lt;pod-ip&gt;</code>为需要查看的基座ip，<code>&lt;pod-name&gt;</code>为需要查看的基座名称，<code>&lt;namespace&gt;</code>为需要查看资源的namespace</p>

</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-cbb99adb1eb306a588e034d68e0481d8">4.5.8 - 模块Service</h1>
    
	<h2 id="moduleservice-简介">ModuleService 简介</h2>
<p>K8S 通过 <a href="https://kubernetes.io/docs/concepts/services-networking/service/">Service</a> ，将运行在一个或一组 Pod 上的网络应用程序公开为网络服务。
模块也支持 Module 相关的 Service ，在模块发布时自动创建一个 service 来服务模块，将安装在一个或一组 Pod 的模块公开为网络服务。
具体见：OperationStrategy.ServiceStrategy</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">apiVersion</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">serverless.alipay.com/v1alpha1</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">kind</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">ModuleDeployment</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">metadata</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">labels</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">app.kubernetes.io/name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">moduledeployment</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">app.kubernetes.io/instance</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">moduledeployment-sample</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">app.kubernetes.io/part-of</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">module-controller</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">app.kubernetes.io/managed-by</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">kustomize</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">app.kubernetes.io/created-by</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">module-controller</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">moduledeployment-sample-provider</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">spec</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">baseDeploymentName</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">dynamic-stock-deployment</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">template</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">spec</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">      </span><span style="color:#204a87;font-weight:bold">module</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">provider</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">version</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#39;1.0.2&#39;</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">url</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">http://serverless-opensource.oss-cn-shanghai.aliyuncs.com/module-packages/stable/dynamic-provider-1.0.2-ark-biz.jar</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">replicas</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">1</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">operationStrategy</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">needConfirm</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">false</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">grayTimeBetweenBatchSeconds</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">120</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">useBeta</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">false</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">batchCount</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">1</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">upgradePolicy</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">install_then_uninstall</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">serviceStrategy</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">      </span><span style="color:#204a87;font-weight:bold">enableModuleService</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">true</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">      </span><span style="color:#204a87;font-weight:bold">port</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">8080</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">      </span><span style="color:#204a87;font-weight:bold">targetPort</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">8080</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">schedulingStrategy</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">schedulingPolicy</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">scatter</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span></code></pre></div><h2 id="字段解释">字段解释</h2>
<p>OperationStrategy.ServiceStrategy 字段解释如下：</p>
<table>
<thead>
<tr>
<th></th>
<th>字段解释</th>
<th>取值范围</th>
</tr>
</thead>
<tbody>
<tr>
<td>EnableModuleService</td>
<td>开启模块service</td>
<td>true or false</td>
</tr>
<tr>
<td>Port</td>
<td>公开的端口</td>
<td>1 到 65535</td>
</tr>
<tr>
<td>TargetPort</td>
<td>pod上要访问的端口</td>
<td>1 到 65535</td>
</tr>
</tbody>
</table>
<h2 id="示例">示例</h2>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>kubectl apply -f sofa-serverless/module-controller/config/samples/module-deployment_v1alpha1_moduledeployment_provider.yaml --namespace yournamespace
</span></span></code></pre></div><p>自动创建的模块的 service</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-yaml" data-lang="yaml"><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">apiVersion</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">v1</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">kind</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Service</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">metadata</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">creationTimestamp</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;2023-11-03T09:52:22Z&#34;</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">dynamic-provider-service</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">namespace</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">default</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">resourceVersion</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;28170024&#34;</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">uid</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">1f85e468-65e3-4181-b40e-48959a069df5</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">spec</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">clusterIP</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">10.0.147.22</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">clusterIPs</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span>- <span style="color:#0000cf;font-weight:bold">10.0.147.22</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">externalTrafficPolicy</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Cluster</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">internalTrafficPolicy</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Cluster</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">ipFamilies</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span>- <span style="color:#000">IPv4</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">ipFamilyPolicy</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">SingleStack</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">ports</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span>- <span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">http</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">nodePort</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">32232</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">port</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">8080</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">protocol</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">TCP</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">targetPort</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">8080</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">selector</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">module.serverless.alipay.com/dynamic-provider</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;true&#34;</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">sessionAffinity</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">None</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">type</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">NodePort</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">status</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">  </span><span style="color:#204a87;font-weight:bold">loadBalancer</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span>{}<span style="color:#f8f8f8;text-decoration:underline">
</span></span></span></code></pre></div>
</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-68c3bb9b1561f186515e61704fac5511">4.5.9 - 所有 K8S 资源定义及部署方式</h1>
    
	<h3 id="资源文件位置">资源文件位置</h3>
<ol>
<li><a href="https://github.com/sofastack/sofa-serverless/blob/master/module-controller/config/crd/bases/serverless.alipay.com_moduledeployments.yaml">ModuleDeployment CRD 定义</a></li>
<li><a href="https://github.com/sofastack/sofa-serverless/blob/master/module-controller/config/crd/bases/serverless.alipay.com_modulereplicasets.yaml">ModuleReplicaset CRD 定义</a></li>
<li><a href="https://github.com/sofastack/sofa-serverless/blob/master/module-controller/config/crd/bases/serverless.alipay.com_moduletemplates.yaml">ModuleTemplate CRD 定义</a></li>
<li><a href="https://github.com/sofastack/sofa-serverless/blob/master/module-controller/config/crd/bases/serverless.alipay.com_modules.yaml">Module CRD 定义</a></li>
<li><a href="https://github.com/sofastack/sofa-serverless/blob/master/module-controller/config/rbac/role.yaml">Role 定义</a></li>
<li><a href="https://github.com/sofastack/sofa-serverless/blob/master/module-controller/config/rbac/role_binding.yaml">RBAC 定义</a></li>
<li><a href="https://github.com/sofastack/sofa-serverless/blob/master/module-controller/config/rbac/service_account.yaml">ServiceAccount 定义</a></li>
<li><a href="https://github.com/sofastack/sofa-serverless/blob/master/module-controller/config/samples/module-deployment-controller.yaml">ModuleController 部署定义</a></li>
</ol>
<h3 id="部署方式">部署方式</h3>
<p>使用 kubectl apply 命令，依次 apply 上述 8 个资源文件，即可完成 ModuleController 部署。</p>
<br/>
<br/>
</div>



    
	
  

    
	
  

    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-99a93ef9534d11fef4be3e4b3b1a6381">5 - 参与社区</h1>
    
	
</div>



    
      
  
  
  
  

  
  

  
    
    
	
    

<div class="td-content" style="">
    
	<h1 id="pg-e29f40edf90bd16bb849d278394baf42">5.1 - 开放包容理念</h1>
    
	<h2 id="核心价值观">核心价值观</h2>
<p>SOFAServerless 社区的核心价值观是 <strong>“开放” 和 “包容”</strong>。社区里所有的用户、开发者<strong>完全平等</strong>，体现在如下几个方面：</p>
<ol>
<li>
<p>社区参考了 Apache 开源项目的运作方式，对社区做出<strong>任意贡献</strong>的同学，尤其是<strong>非代码贡献</strong>的同学（文档、官网、Issue 回复、运营布道、发展建议等），都是我们的 Contributor，都有机会成为社区的 Committer 甚至是 PMC（Project Management Committee）成员。</p>
</li>
<li>
<p>社区所有的 OKR、RoadMap、讨论、会议、技术方案等都是<strong>完全开放的</strong>，所有人都可以看见，并且都可以参与其中，社区会认证倾听、考虑大家的所有建议和意见，一旦采纳就会确保执行落地。希望大家带着<strong>无所顾虑</strong>、求同<strong>尊异</strong>的心态参与 SOFAServerless 社区。</p>
</li>
<li>
<p>社区不限地域国籍，所有源代码必须是<strong>英文注释</strong>确保大家都能理解，官网也是中英文双语。所有微信群、钉钉群、GitHub Issues 讨论都可以是<strong>中英双语</strong>。但由于当前我们主要聚焦在国内用户，因此大部分文档暂时只有中文版，未来会提供英文版。</p>
</li>
</ol>
<h2 id="2023-年-okr">2023 年 OKR</h2>
<h3 id="o1--打造社区健康有行业影响力的-serverless-开源产品">O1  打造社区健康、有行业影响力的 Serverless 开源产品</h3>
<h4 id="kr1--新增-10-个-contributors年底-openrank-指数--15当前-5活跃度--50当前-44">KR1  新增 10 个 Contributors，年底 OpenRank 指数 &gt; 15（当前 5）、活跃度 &gt; 50（当前 44）</h4>
<p><strong>KR1.1</strong>  完成 5 次布道和 5 次文章分享，触达 200 家企业，深度交流 30+ 企业。<br />
<strong>KR1.2</strong>  形成完善的社区共建机制（包括 Issue 管理、文档、问题响应、培养与晋升机制），发布 2+ 培训课程与产品手册，共建开发者可在一周内上手，开发总吞吐率达到 20+ Issues/周。</p>
<h4 id="kr2--新增-5-家企业在生产环境使用或完成试点接入当前新增-13-家企业参与社区">KR2  新增 5 家企业在生产环境使用或完成试点接入（当前新增 1），3 家企业参与社区</h4>
<p><strong>KR2.1</strong>  产出初步行业分析报告，帮助定位适用不同场景的重点企业对象。<br />
<strong>KR2.2</strong>  5 家企业生产真实使用或完成试点接入，3 家企业参与社区，覆盖 3 个场景并沉淀 3+ 用户案例。</p>
<h3 id="o2--打造技术先进效果显著的降本增效解决方案">O2  打造技术先进、效果显著的降本增效解决方案</h3>
<h4 id="kr1--落地模块化技术实现机器减少-30部署验证耗时降低至-30-秒需求交付效率提升-50">KR1  落地模块化技术实现机器减少 30%、部署验证耗时降低至 30 秒、需求交付效率提升 50%</h4>
<p><strong>KR1.1</strong>  搭建 1 分钟快速试用平台，完善的文档、官网与配套支持，用户可在 10 分钟完成一个模块拆分。<br />
<strong>KR1.2</strong>  完成 20 种中间件和三方包治理，同时形成多应用与热卸载评测和自动检测标准。<br />
<strong>KR1.3</strong>  模块具备热部署启动耗时降低至 10 秒级，多模块具备合并部署资源减少 30%，同时让用户需求交付效率提升 50%。<br />
<strong>KR1.4</strong>  落地开源版 Arklet，支持 SOFABoot 和 SpringBoot。提供运维管道、指标采集、模块生命周期管理、多模块运行环境、Bean 与服务发现及调用能力。<br />
<strong>KR1.5</strong>  落地研发工具 ArkCtl，具备快速开发验证、灵活部署（合并与独立部署）、模块低成本拆分改造能力。</p>
<h4 id="kr2--运维调度-10-版本上线全链路高频端到端测试用例成功率-999自身端到端耗时-p90--500ms">KR2  运维调度 1.0 版本上线。全链路高频端到端测试用例成功率 99.9%，自身端到端耗时 P90 &lt; 500ms</h4>
<p><strong>KR2.1</strong>  上线基于 K8S Operator 的开源版运维调度能力，至少具备发布、回滚、下线、扩缩容、替换、副本保持、2+ 调度策略、模块流控、部署策略、对等和非对等运维能力。<br />
<strong>KR2.2</strong>  建设开源版 CI 和 25+ 高频端到端测试用例，不断打磨并推动端到端 P90 耗时 &lt; 500ms、所有预演成功率&gt; 99.9%、单测覆盖率达到行 &gt; 80% 分支 &gt; 60%（通过率 100%）。</p>
<h4 id="kr3--开源版自动伸缩初步上线模块具备人工画像和分时伸缩能力">KR3  开源版<strong>自动伸缩初步</strong>上线，模块具备人工画像和分时伸缩能力</h4>
<h2 id="roadmap">RoadMap</h2>
<ul>
<li>2023.08  完成 SOFABoot 完整的部署功能验证，产出兼容性 Benchmark 基线。</li>
<li>2023.09  发布基础运维和调度系统 ModuleController 0.5 版本。</li>
<li>2023.09  发布研发运维工具 Arkctl 与 Arklet 0.5 版本。</li>
<li>2023.09  官网和完整用户手册上线。</li>
<li>2023.10  新增 2+ 公司使用。</li>
<li>2023.11  支持 SpringBoot 完整能力和 5+ 社区常用中间件。</li>
<li>2023.11  SOFAServerless 1.0 版本上线（ModuleController、Arkctl、Arklet、SpringBoot 兼容）。</li>
<li>2023.12  SOFAServerless 1.1 版本上线（包括基础自动伸缩、模块基础拆分工具、20+ 中间件与三方包兼容）。</li>
<li>2023.12  新增 5+ 家公司真实使用，10+ Contributors 参与。</li>
</ul>
<br/>
<br/>
</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-602e76c3bdfe995632399d8611c22fa3">5.2 - 交流渠道</h1>
    
	<p>SOFAServerless 提供如下沟通交流渠道，欢迎加入我们一起分享、一起使用、一起收获：</p>
<h4 id="sofaserverless-社区交流与协作钉钉群24970018417">SOFAServerless 社区交流与协作钉钉群：24970018417</h4>
<p>如果您对 SOFAServerless 感兴趣、或者有初步意向使用 SOFAServerless、或者已经是 SOFAServerless / SOFAArk 的用户、或者有兴趣成为社区 Contributor，都可以加入该钉钉群和我们随时随地一起交流讨论、一起贡献代码。<br/>
<img width="200px" src="/img/dingtalk-qcode.png" /></p>
<h4 id="sofaserverless-用户微信群">SOFAServerless 用户微信群</h4>
<img width="200px" src="/img/wechat-qcode.png" />
<br/>
如果您对 SOFAServerless 感兴趣、或者有初步意向使用 SOFAServerless、或者已经是 SOFAServerless / SOFAArk 的用户，都可以加入该微信群随时随地一起交流讨论。<br/>
<br/>
<h4 id="社区双周会">社区双周会</h4>
<p><strong>每两周周二晚 19:30 - 20:30 会举办社区会议</strong>，下次社区双周会时间：2023 年 11 月 28 日 19:30 ~ 20:30，欢迎大家积极参与旁听或讨论。社区钉钉会议入会方式：<br />
入会链接：<a href="https://meeting.dingtalk.com/j/blp36k9mTbc">https://meeting.dingtalk.com/j/blp36k9mTbc</a><br />
钉钉会议号：90957500367<br />电话呼入：+867936169179 (中国大陆)、+867388953916 (中国大陆)<br />
<strong>具体会议时间也可关注社区钉钉协作群（群号：24970018417）</strong>。</p>
<br/>
<p>每个月底的周一会召开社区各组件 PMC 成员迭代规划会议，讨论并敲定下一个月需求规划。下次 PMC 成员月会时间：2023 年 11 月 27 日 19:30 ~ 20:30。入会方式同上。</p>
<br/>
<br/>

</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-a473df27e2a59f4a48f7ec005f1be08d">5.3 - 贡献社区</h1>
    
	
</div>



    
      
  
  
  
  

  
  

  
    
    
	
    

<div class="td-content" style="">
    
	<h1 id="pg-2116f3408dfc680cc19d506d77f5894a">5.3.1 - 本地开发测试</h1>
    
	<h2 id="sofaark-和-arklet">SOFAArk 和 Arklet</h2>
<p>SOFAArk 是一个普通 Java SDK 项目，使用 Maven 作为依赖管理和构建工具，只需要本地安装 Maven 3.6 及以上版本即可正常开发代码和单元测试，无需其它的环境准备工作。<br />关于代码提交细节请参考：<a href="../first-pr">完成第一次 PR 提交</a>。</p>
<h2 id="modulecontroller">ModuleController</h2>
<p>ModuleController 是一个标准的 K8S Golang Operator 组件，里面包含了 ModuleDeployment Operator、ModuleReplicaSet Operator、Module Operator，在本地可以使用 minikube 做开发测试，具体请参考<a href="/docs/quick-start">本地快速开始</a>。<br />
编译构建请在 module-controller 目录下执行：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>go mod download   <span style="color:#8f5902;font-style:italic"># if compile module-controller first time</span>
</span></span><span style="display:flex;"><span>go build -a -o manager cmd/main.go  
</span></span></code></pre></div><p>单元测试执行请在 module-controller 目录下执行：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-bash" data-lang="bash"><span style="display:flex;"><span>make <span style="color:#204a87">test</span>
</span></span></code></pre></div><p>您也可以使用 IDE 进行编译构建、开发调试和单元测试执行。<br />
module-controller 开发方式和标准 K8S Operator 开发方式完全一样，您可以参考 K8S Operator 开发<a href="https://kubernetes.io/zh-cn/docs/concepts/extend-kubernetes/operator/">官方文档</a>。</p>
<h2 id="arkctl">Arkctl</h2>
<p>Arkctl 是一个普通 Golang 项目，他是一个命令行工具集，包含了用户在本地开发和运维模块过程中的常用工具，它和普通 Golang 程序开发完全一样，<em>当前初始版本还在开发中</em>。</p>
<br/>

</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-5726ff7fce2c3ff40a2cd82591c376cc">5.3.2 - 完成第一次 PR 提交</h1>
    
	<h2 id="认领或提交-issue">认领或提交 Issue</h2>
<p>不论您是修复 bug、新增功能或者改进现有功能，在您提交代码之前，请在 <a href="https://github.com/sofastack/sofa-serverless">SOFAServerless</a> 或 <a href="https://github.com/sofastack/sofa-ark">SOFAArk</a> GitHub 上认领一个 Issue 并将 Assignee 指定为自己（新人建议认领 <b>good-first-issue</b> 标签的新手任务）。或者提交一个新的 Issue，描述您要修复的问题或者要增加、改进的功能。这样做的好处是能避免与其他人的<strong>工作重复</strong>。</p>
<h2 id="获取源码">获取源码</h2>
<p>要修改或新增功能，在提 Issue 或者领取现有 Issue 后，点击左上角的<code>fork</code>按钮，复制一份 SOFAServerless 或 SOFAArk 主干代码到您的代码仓库。</p>
<h2 id="拉分支">拉分支</h2>
<p>SOFAServerless 和 SOFAArk 所有修改都在个人分支上进行，修改完后提交 <code>pull request</code>，当前在跑通 PR 流水线之后，会由相应组件的 PMC 或 Maintainer 负责 Review 与合并代码到主干（master）。因此，在 fork 源码后，您需要：</p>
<ul>
<li>下载代码到本地，这一步您可以选择 git/https 方式：</li>
</ul>
<pre tabindex="0"><code>git clone https://github.com/您的账号名/sofa-serverless.git
</code></pre><pre tabindex="0"><code>git clone https://github.com/您的账号名/sofa-ark.git
</code></pre><ul>
<li>拉分支准备修改代码：</li>
</ul>
<pre tabindex="0"><code>git branch add_xxx_feature
</code></pre><p><br />执行完上述命令后，您的代码仓库就切换到相应分支了。执行如下命令可以看到您当前分支：</p>
<pre tabindex="0"><code>  git branch -a
</code></pre><p>如果您想切换回主干，执行下面命令：</p>
<pre tabindex="0"><code>  git checkout -b master
</code></pre><p>如果您想切换回分支，执行下面命令：</p>
<pre tabindex="0"><code>  git checkout -b &#34;branchName&#34;
</code></pre><h2 id="修改代码提交到本地">修改代码提交到本地</h2>
<p>拉完分支后，就可以修改代码了。</p>
<h3 id="修改代码注意事项">修改代码注意事项</h3>
<ul>
<li>代码风格保持一致。SOFAServerless arklet 和 sofa-ark 通过 Maven 插件来保持代码格式一致，在提交代码前，务必先本地执行：</li>
</ul>
<pre tabindex="0"><code>mvn clean compile
</code></pre><p>module-controller 和 arkctl Golang 代码的格式化能力还在建设中。</p>
<ul>
<li>补充单元测试代码。</li>
<li>确保新修改通过所有单元测试。</li>
<li>如果是 bug 修复，应该提供新的单元测试来证明以前的代码存在 bug，而新的代码已经解决了这些 bug。对于 arklet 和 sofa-ark 您可以用如下命令运行所有测试：</li>
</ul>
<pre tabindex="0"><code>mvn clean test
</code></pre><p>对于 module-controller 和 arkctl，您可以用如下命令运行所有测试：</p>
<pre tabindex="0"><code>make test
</code></pre><p>也可以通过 IDE 来辅助运行。</p>
<h3 id="其它注意事项">其它注意事项</h3>
<ul>
<li>请保持您编辑的代码使用原有风格，尤其是空格换行等。</li>
<li>对于无用的注释，请直接删除。注释必须使用英文。</li>
<li>对逻辑和功能不容易被理解的地方添加注释。</li>
<li>务必第一时间更新 docs/content/zh-cn/ 目录中的 “docs”、“contribution-guidelines” 目录中的相关文档。</li>
</ul>
<p>修改完代码后，执行如下命令提交所有修改到本地：</p>
<pre tabindex="0"><code>git commit -am &#39;添加xx功能&#39;
</code></pre><h2 id="提交代码到远程仓库">提交代码到远程仓库</h2>
<p>在代码提交到本地后，就是与远程仓库同步代码了。执行如下命令提交本地修改到 github 上：</p>
<pre tabindex="0"><code>git push origin &#34;branchname&#34;
</code></pre><p>如果前面您是通过 fork 来做的，那么这里的 origin 是 push 到您的代码仓库，而不是 SOFAServerless 的代码仓库。</p>
<h2 id="提交合并代码到主干的请求">提交合并代码到主干的请求</h2>
<p>在的代码提交到 GitHub 后，您就可以发送请求来把您改好的代码合入 SOFAServerless 或 SOFAArk 主干代码了。此时您需要进入您的 GitHub 上的对应仓库，按右上角的 <code>pull request</code>按钮。选择目标分支，一般就是 <code>master</code>，当前需要选择组件的 <a href="../../role-and-promotion#member-list">Maintainer</a> 或 <a href="../../role-and-promotion#member-list">PMC</a> 作为 Code Reviewer，如果 PR 流水线校验和 Code Review 都通过，您的代码就会合入主干成为 SOFAServerless 的一部分。</p>
<h3 id="pr-流水线校验">PR 流水线校验</h3>
<p>PR 流水线校验包括：</p>
<ol>
<li>CLA 签署。第一次提交 PR 必须完成 CLA 协议的签署，如果打不开 CLA 签署页面请尝试使用代理。</li>
<li>自动为每个文件追加 Apache 2.0 License 声明和作者。</li>
<li>执行全部单元测试且必须全部通过。</li>
<li>检测覆盖率是否达到行覆盖 &gt;= 80%，分支覆盖 &gt;= 60%。</li>
<li>检测提交的代码是否存在安全漏洞。</li>
<li>检测提交的代码是否符合基本代码规范。</li>
</ol>
<p>以上校验必须全部通过，PR 流水线才会通过并进入到 Code Review 环节。</p>
<h3 id="code-review">Code Review</h3>
<p>当您选择对应组件的 <a href="../../role-and-promotion#member-list">Maintainer</a> 或 <a href="../../role-member-list#member-list">PMC</a> 作为 Code Reviewer 数天后，仍然没有人对您的提交给予任何回复，可以在 PR 下面留言并 at 相关人员，或者在社区钉钉协作群中（钉钉群号：24970018417）直接 at 相关人员 Review 代码。对于 Code Review 的意见，Code Reviewer 会直接备注到到对应的 PR 或者 Issue 中，如果您觉得建议是合理的，也请您把这些建议更新到您的代码中并重新提交 PR。</p>
<h3 id="合并代码到主干">合并代码到主干</h3>
<p>在 PR 流水线校验和 Code Review 都通过后，就由 SOFAServerless 维护人员操作合入主干了，代码合并之后您会收到合并成功的提示。</p>
<br/>

</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-6c5458a163d621b3a719a2d5b3973530">5.3.3 - 文档、Issue、流程贡献</h1>
    
	<h2 id="文档贡献">文档贡献</h2>
<p>使用文档、技术文档、官网内容需要社区每一位 Contributor 共同维护，对任意文档和官网内容做出贡献的同学都是我们的 Contributor，并且根据活跃度有机会成为 SOFAServerless 组件的 Committer 甚至 PMC 成员，共同主导 SOFAServerless 的技术演进。<br/><br/></p>
<h2 id="issue-提交与回复贡献">Issue 提交与回复贡献</h2>
<p>任何使用过程中的问题、Bug、新功能、改进优化请创建 GitHub Issue，社区每天会有值班同学负责跟进 Issue。任何人提出或者回复 Issue 都是 SOFAServerless 的 Contributor，对回复 Issue 活跃的 Contributor 可以晋升为 Committer，如果特别活跃甚至可以晋升为 PMC 成员，共同主导 SOFAServerless 的技术演进。</p>
<h3 id="issue-模板">Issue 模板</h3>
<p>SOFAServerless（含 SOFAArk）Issue 有两种模板，一种是 “Question or Bug Report”，一种是 “Feature Request”。<br /><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/671/1694089517798-6930c476-c675-44c1-8e76-9f98166f0645.png#clientId=uab052d98-bf90-4&amp;from=paste&amp;height=182&amp;id=u345d4d11&amp;originHeight=364&amp;originWidth=2358&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=156188&amp;status=done&amp;style=none&amp;taskId=ufbd6f12c-1e4f-4de5-a74c-a951ddabfac&amp;title=&amp;width=1179" alt="image.png"></p>
<h3 id="question-or-bug-report">Question or Bug Report</h3>
<p>所有使用过程中遇到的问题或者疑似 Bug，请选择 “Question or Bug Report”，并提供详细的复现信息如下：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#a40000">###</span> <span style="color:#a40000">Describe</span> <span style="color:#a40000">the</span> <span style="color:#a40000">question</span> <span style="color:#a40000">or</span> <span style="color:#a40000">bug</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a40000">A</span> <span style="color:#a40000">clear</span> <span style="color:#a40000">and</span> <span style="color:#a40000">concise</span> <span style="color:#a40000">description</span> <span style="color:#a40000">of</span> <span style="color:#a40000">what</span> <span style="color:#a40000">the</span> <span style="color:#a40000">question</span> <span style="color:#a40000">or</span> <span style="color:#a40000">bug</span> <span style="color:#a40000">is.</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a40000">###</span> <span style="color:#a40000">Expected</span> <span style="color:#a40000">behavior</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a40000">A</span> <span style="color:#a40000">clear</span> <span style="color:#a40000">and</span> <span style="color:#a40000">concise</span> <span style="color:#a40000">description</span> <span style="color:#a40000">of</span> <span style="color:#a40000">what</span> <span style="color:#a40000">you</span> <span style="color:#a40000">expected</span> <span style="color:#a40000">to</span> <span style="color:#a40000">happen.</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a40000">###</span> <span style="color:#a40000">Actual</span> <span style="color:#a40000">behavior</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a40000">A</span> <span style="color:#a40000">clear</span> <span style="color:#a40000">and</span> <span style="color:#a40000">concise</span> <span style="color:#a40000">description</span> <span style="color:#a40000">of</span> <span style="color:#a40000">what</span> <span style="color:#a40000">actually</span> <span style="color:#a40000">happened.</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a40000">###</span> <span style="color:#a40000">Steps</span> <span style="color:#a40000">to</span> <span style="color:#a40000">reproduce</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a40000">Steps</span> <span style="color:#a40000">to</span> <span style="color:#a40000">reproduce</span> <span style="color:#a40000">the</span> <span style="color:#a40000">problem:</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#0000cf;font-weight:bold">1</span><span style="color:#a40000">.</span> <span style="color:#a40000">Go</span> <span style="color:#a40000">to</span> <span style="color:#a40000">&#39;...&#39;</span>
</span></span><span style="display:flex;"><span><span style="color:#0000cf;font-weight:bold">2</span><span style="color:#a40000">.</span> <span style="color:#a40000">Click</span> <span style="color:#a40000">on</span> <span style="color:#a40000">&#39;....&#39;</span>
</span></span><span style="display:flex;"><span><span style="color:#0000cf;font-weight:bold">3</span><span style="color:#a40000">.</span> <span style="color:#a40000">Scroll</span> <span style="color:#a40000">down</span> <span style="color:#a40000">to</span> <span style="color:#a40000">&#39;....&#39;</span>
</span></span><span style="display:flex;"><span><span style="color:#0000cf;font-weight:bold">4</span><span style="color:#a40000">.</span> <span style="color:#a40000">See</span> <span style="color:#a40000">error</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a40000">###</span> <span style="color:#a40000">Screenshots</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a40000">If</span> <span style="color:#a40000">applicable,</span> <span style="color:#a40000">add</span> <span style="color:#a40000">screenshots</span> <span style="color:#a40000">to</span> <span style="color:#a40000">help</span> <span style="color:#a40000">explain</span> <span style="color:#a40000">your</span> <span style="color:#a40000">problem.</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a40000">###</span> <span style="color:#a40000">Minimal</span> <span style="color:#a40000">yet</span> <span style="color:#a40000">complete</span> <span style="color:#a40000">reproducer</span> <span style="color:#a40000">code</span> <span style="color:#a40000">(or</span> <span style="color:#a40000">GitHub</span> <span style="color:#a40000">URL</span> <span style="color:#a40000">to</span> <span style="color:#a40000">code)</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a40000">###</span> <span style="color:#a40000">Environment</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#a40000">-</span> <span style="color:#a40000">SOFAArk</span> <span style="color:#a40000">version:</span>
</span></span><span style="display:flex;"><span><span style="color:#a40000">-</span> <span style="color:#a40000">JVM</span> <span style="color:#a40000">version</span> <span style="color:#a40000">(e.g.</span> <span style="color:#a40000">`java</span> <span style="color:#a40000">-version`):</span>
</span></span><span style="display:flex;"><span><span style="color:#a40000">-</span> <span style="color:#a40000">OS</span> <span style="color:#a40000">version</span> <span style="color:#a40000">(e.g.</span> <span style="color:#a40000">`uname</span> <span style="color:#a40000">-a`):</span>
</span></span><span style="display:flex;"><span><span style="color:#a40000">-</span> <span style="color:#a40000">Maven</span> <span style="color:#a40000">version:</span>
</span></span><span style="display:flex;"><span><span style="color:#a40000">-</span> <span style="color:#a40000">IDE</span> <span style="color:#a40000">version:</span>
</span></span></code></pre></div><h3 id="feature-request">Feature Request</h3>
<p>新功能、已有功能改进优化或者其它讨论，请选择 “Feature Request”。</p>
<h2 id="流程贡献">流程贡献</h2>
<p>SOFAServerless 当前制定了代码规约、PR 流程、CI 流水线、迭代管理、周会、交流渠道等各种协作规范，您可以对我们的协作规范和流程在 GitHub 上提出建议，即可成为我们的 Contributor。</p>
<br/>
<br/>

</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-d890a1e9140aca7ee684208abba11a5f">5.3.4 - 组织会议和运营布道</h1>
    
	<p>我们鼓励大家宣传、布道 SOFAServerless，通过运营成为 SOFAServerless 的 Contributor、Committer 甚至 PMC，每一次 Contributor 的晋升，我们也会发放纪念品奖励。运营方式包括但不限于：</p>
<ol>
<li>在线上或线下技术会议、Meetup 中发表 SOFAServerless 的使用或者技术实现相关演讲。</li>
<li>与其他企业分享交流 SOFAServerless 的使用场景等。</li>
<li>在各种渠道发表关于 SOFAServerless 的使用或者技术实现相关文章或视频。</li>
<li>其它运营方式。</li>
</ol>
<br/>

</div>



    
	
  

    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-20720f61569788d3fa4a197db902e640">5.4 - 社区角色与晋升</h1>
    
	<h2 id="角色职责与晋升机制">角色职责与晋升机制</h2>
<p>SOFAServerless 社区角色参考了 Apache 开源产品组织方式，SOFAArk、Arklet、ModuleController、ArkCtl 每个组件都有各自的角色。每个组件的角色职责从低到高分别是：<strong>Contributor、Committer、PMC (Project Management Committee)、Maintainer</strong>。<br/></p>
<table>
<thead>
<tr>
<th>角色</th>
<th>责任与权限</th>
<th>晋升到更高角色机制</th>
</tr>
</thead>
<tbody>
<tr>
<td>Contributor</td>
<td>所有在社区提 <strong>Issue</strong>、回答 Issue、对外<strong>运营</strong>、提交<strong>文档</strong>内容或者提交任意<strong>代码</strong>的同学，都是相应组件的 <strong>Contributor</strong>。Contributor 拥有 Issue 提交、Issue 回复、官网或文档内容提交、代码提交（不包括代码评审）和对外发表文章权限。</td>
<td>当 Contributor 完成合并的代码或者文档内容足够多，就可以由该组件的 PMC 成员投票晋升为 Committer。当 Contributor 回答的 Issue 或者参与的运营活动足够多，也可以被 PMC 成员投票晋升为 Committer。</td>
</tr>
<tr>
<td>Committer</td>
<td>所有在社区积极回答 <strong>Issue</strong>、对外<strong>运营</strong>、提交<strong>文档</strong>内容或者提交<strong>代码</strong>的同学，按积极度都有可能被 PMC 成员投票晋升为 <strong>Committer</strong>。Committer 额外拥有代码<strong>评审</strong>、技术方案评审、Contributor <strong>培养</strong>的责任与权限。</td>
<td>对长期积极投入或持续有突出贡献的 Committer，经 PMC 成员投票可以晋升为相应组件的 PMC 成员。</td>
</tr>
<tr>
<td>PMC</td>
<td>对相应组件<strong>持续贡献</strong>且<strong>特别活跃</strong>的同学有机会晋升为 <strong>PMC</strong> 成员。PMC 成员额外拥有组件的 <strong>RoadMap</strong> 制定、技术<strong>方案</strong>和代码<strong>评审</strong>、Issue 和<strong>迭代管理</strong>、Contributor 和 Committer <strong>培养</strong>等责任与权限。</td>
<td></td>
</tr>
<tr>
<td>Maintainer</td>
<td>Maintainer 额外拥有密钥管理和仓库管理等管理员权限，除此之外在其他方面和 PMC 成员的责任与权限是<strong>完全对等</strong>的。</td>
<td></td>
</tr>
</tbody>
</table>
<h2 id="社区角色成员名单">社区角色成员名单</h2>
<h3 id="sofaark">SOFAArk</h3>
<h4 id="maintainer">Maintainer</h4>
<p>yuanyuancin<br />lvjing2</p>
<h4 id="pmc-project-management-comittee">PMC (Project Management Comittee)</h4>
<p>glmapper</p>
<h4 id="committer">Committer</h4>
<p>zjulbj5<br />gaosaroma<br />QilongZhang133<br />straybirdzls13<br />caojie0911</p>
<h4 id="contributor">Contributor</h4>
<p>lylingzhen10<br />khotyn<br />FlyAbner   （260+ 行提交，提名 Comitter？）<br />alaneuler<br />sususama<br />ujjboy<br />JoeKerouac<br />Lunarscave<br />HzjNeverStop<br />AiWu4Damon<br />vchangpengfei<br />HuangDayu<br />shenchao45<br />DalianRollingKing<br />nobodyiam<br />lanicc<br />azhsmesos<br />wuqian0808<br />KangZhiDong<br />suntao4019<br />huangyunbin<br />jiangyunpeng<br />michalyao<br />rootsongjc<br />Zwl0113<br />tofdragon<br />lishiguang4<br />hionwi<br />343585776<br />g-stream<br />zkitcast<br />davidzj<br />zyclove<br />WindSearcher<br />lovejin52022<br />smalljunHw<br />vchangpengfei<br />sq1015<br />xwh1108<br />yuanChina<br />blysin<br />yuwenkai666<br />hadoop835<br />gitYupan<br />thirdparty-core<br />Estom<br />jijuanwang<br />DCLe-DA<br />linkoog<br />springcoco<br />zhaowwwjian<br />xingcici<br />ixufeng<br />jnan806<br />lizhi12q<br />kongqq<br />wangxiaotao00<br />由于篇幅有限，23 年之前提交 Issue 的 Contributor 不在此一一列举，也同样感谢大家对 SOFAArk 的使用和咨询</p>
<h3 id="arklet">Arklet</h3>
<h4 id="maintainer-1">Maintainer</h4>
<p>yuanyuancin<br />lvjing2</p>
<h4 id="pmc-project-management-committee">PMC (Project Management Committee)</h4>
<p>TomorJM</p>
<h4 id="committer-1">Committer</h4>
<p>暂无</p>
<h4 id="contributor-1">Contributor</h4>
<p>glmapper<br />Lunarscave<br />lylingzhen</p>
<h3 id="modulecontroller">ModuleController</h3>
<h4 id="maintainer-2">Maintainer</h4>
<p>gold300jin</p>
<h4 id="pmc-project-management-committee-1">PMC (Project Management Committee)</h4>
<p>暂无</p>
<h4 id="committer-2">Committer</h4>
<p>暂无</p>
<h4 id="contributor-2">Contributor</h4>
<p>liu-657667<br />Charlie17Li<br />lylingzhen</p>
<h3 id="arkctl">Arkctl</h3>
<h4 id="maintainer-3">Maintainer</h4>
<p>yuanyuancin<br />lvjing2</p>
<h4 id="pmc-project-management-committee-2">PMC (Project Management Committee)</h4>
<p>暂无</p>
<h4 id="committer-3">Committer</h4>
<p>暂无</p>
<h4 id="contributor-3">Contributor</h4>
<p>暂无</p>
<br/>
</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-00e955e7b325b37beabf9dc83947c176">5.5 - SOFAArk 技术文档</h1>
    
	<p><a href="https://www.sofastack.tech/projects/sofa-boot/sofa-ark-migration-guide/">SOFAArk 2.0 介绍</a> <br/>
<a href="https://www.sofastack.tech/projects/sofa-boot/sofa-ark-startup/">Ark 容器启动流程</a> <br/>
<a href="https://www.sofastack.tech/projects/sofa-boot/sofa-ark-plugin/">Ark 容器插件机制</a> <br/>
<a href="https://www.sofastack.tech/projects/sofa-boot/sofa-ark-classloader/">Ark 容器类加载机制</a> <br/>
<a href="https://www.sofastack.tech/projects/sofa-boot/sofa-ark-build-package-plugin/">打包插件源码解析</a> <br/>
<a href="https://www.sofastack.tech/projects/sofa-boot/sofa-ark-startup-process/">启动过程源码解析</a> <br/>
<a href="https://www.sofastack.tech/projects/sofa-boot/sofa-ark-dynamic-deploy/">动态热部署源码解析</a> <br/>
<a href="https://www.sofastack.tech/projects/sofa-boot/sofa-ark-class-loader-delegation/">类委托加载源码解析</a> <br/>
<a href="https://www.sofastack.tech/projects/sofa-boot/sofa-ark-multi-web-component-deploy/">多 Web 应用合并部署源码解析</a> <br/></p>
<br/>

</div>



    
      
  
  
  
  

  
  

  

    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-9ae993d6fa8ac20662cf30a0e33bd534">5.6 - Arklet 技术文档</h1>
    
	
</div>



    
      
  
  
  
  

  
  

  
    
    
	
    

<div class="td-content" style="">
    
	<h1 id="pg-44f8de035a733443de71918dd607b8ae">5.6.1 - Arklet 架构设计与接口设计</h1>
    
	<h1 id="概述">概述</h1>
<p>Arklet 为 SofaArk 基础和模块的交付提供了一个操作接口。有了 Arklet，Ark Biz 的发布和操作可以轻松灵活地进行。</p>
<p>Arklet 是由 <strong>ArkletComponent</strong> 内部构建的</p>
<p><img src="https://github.com/sofastack/sofa-serverless/assets/11410549/a2740422-569e-4dd3-9c9a-1503996bd2f1" alt="image"></p>
<ul>
<li>ApiClient: 负责与外界交互的核心组件</li>
<li>CommandService: Arklet 对外暴露能力指令定义和扩展</li>
<li>OperationService: Ark Biz 与 SofaArk 交互，进行添加、删除、修改和封装基本能力</li>
<li>HealthService: 基于健康和稳定性，计算基础、Biz、系统等其他指标</li>
</ul>
<p>他们之间的协作如图所示
<img src="https://user-images.githubusercontent.com/11410549/266193839-7865e417-6909-4e89-bd48-c926162eaf83.jpg" alt="overview"></p>
<p>当然，您也可以通过实现 <strong>ArkletComponent</strong> 接口来扩展 Arklet 的组件功能</p>
<h1 id="命令扩展">命令扩展</h1>
<p>Arklet 外部公开了指令 API，并通过每个 API 映射的 CommandHandler 内部处理指令。</p>
<blockquote>
<p>CommandHandler 相关的扩展属于 CommandService 组件的统一管理</p>
</blockquote>
<p>您可以通过继承 <strong>AbstractCommandHandler</strong> 来自定义扩展命令</p>
<h2 id="内置命令-api">内置命令 API</h2>
<p>以下所有的指令 api 都使用 POST(application/json) 请求格式访问 arklet</p>
<p>启用了 http 协议，默认端口是 1238</p>
<blockquote>
<p>您可以设置 <code>sofa.serverless.arklet.http.port</code> JVM 启动参数覆盖默认端口</p>
</blockquote>
<h2 id="查询支持的命令">查询支持的命令</h2>
<ul>
<li>URL: 127.0.0.1:1238/help</li>
<li>输入样例:</li>
</ul>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{}</span>
</span></span></code></pre></div><ul>
<li>输出样例:</li>
</ul>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;code&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;SUCCESS&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;data&#34;</span><span style="color:#000;font-weight:bold">:[</span>
</span></span><span style="display:flex;"><span>        <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&#34;desc&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;query all ark biz(including master biz)&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&#34;id&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;queryAllBiz&#34;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#000;font-weight:bold">},</span>
</span></span><span style="display:flex;"><span>        <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&#34;desc&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;list all supported commands&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&#34;id&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;help&#34;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#000;font-weight:bold">},</span>
</span></span><span style="display:flex;"><span>        <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&#34;desc&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;uninstall one ark biz&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&#34;id&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;uninstallBiz&#34;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#000;font-weight:bold">},</span>
</span></span><span style="display:flex;"><span>        <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&#34;desc&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;switch one ark biz&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&#34;id&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;switchBiz&#34;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#000;font-weight:bold">},</span>
</span></span><span style="display:flex;"><span>        <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&#34;desc&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;install one ark biz&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&#34;id&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;installBiz&#34;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#000;font-weight:bold">}</span>
</span></span><span style="display:flex;"><span>    <span style="color:#000;font-weight:bold">]</span>
</span></span><span style="display:flex;"><span><span style="color:#000;font-weight:bold">}</span>
</span></span></code></pre></div><h2 id="安装一个-biz">安装一个 biz</h2>
<ul>
<li>URL: 127.0.0.1:1238/installBiz</li>
<li>输入样例:</li>
</ul>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;bizName&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;test&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;bizVersion&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;1.0.0&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#8f5902;font-style:italic">// local path should start with file://, alse support remote url which can be downloaded
</span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span>    <span style="color:#204a87;font-weight:bold">&#34;bizUrl&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;file:///Users/jaimezhang/workspace/github/sofa-ark-dynamic-guides/dynamic-provider/target/dynamic-provider-1.0.0-ark-biz.jar&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#000;font-weight:bold">}</span>
</span></span></code></pre></div><ul>
<li>输出样例(成功):</li>
</ul>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#204a87;font-weight:bold">&#34;code&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;SUCCESS&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>  <span style="color:#204a87;font-weight:bold">&#34;data&#34;</span><span style="color:#000;font-weight:bold">:{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;bizInfos&#34;</span><span style="color:#000;font-weight:bold">:[</span>
</span></span><span style="display:flex;"><span>      <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;bizName&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;dynamic-provider&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;bizState&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;ACTIVATED&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;bizVersion&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;1.0.0&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;declaredMode&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#204a87;font-weight:bold">true</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;identity&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;dynamic-provider:1.0.0&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;mainClass&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;io.sofastack.dynamic.provider.ProviderApplication&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;priority&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#0000cf;font-weight:bold">100</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;webContextPath&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;provider&#34;</span>
</span></span><span style="display:flex;"><span>      <span style="color:#000;font-weight:bold">}</span>
</span></span><span style="display:flex;"><span>    <span style="color:#000;font-weight:bold">],</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;code&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;SUCCESS&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;message&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;Install Biz: dynamic-provider:1.0.0 success, cost: 1092 ms, started at: 16:07:47,769&#34;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#000;font-weight:bold">}</span>
</span></span><span style="display:flex;"><span><span style="color:#000;font-weight:bold">}</span>
</span></span></code></pre></div><p>-输出样例(失败):</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#204a87;font-weight:bold">&#34;code&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;FAILED&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>  <span style="color:#204a87;font-weight:bold">&#34;data&#34;</span><span style="color:#000;font-weight:bold">:{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;code&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;REPEAT_BIZ&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;message&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;Biz: dynamic-provider:1.0.0 has been installed or registered.&#34;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#000;font-weight:bold">}</span>
</span></span><span style="display:flex;"><span><span style="color:#000;font-weight:bold">}</span>
</span></span></code></pre></div><h2 id="卸载模块">卸载模块</h2>
<ul>
<li>URL: 127.0.0.1:1238/uninstallBiz</li>
<li>输入样例:</li>
</ul>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;bizName&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;dynamic-provider&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;bizVersion&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;1.0.0&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#000;font-weight:bold">}</span>
</span></span></code></pre></div><p>-输出样例(成功):</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#204a87;font-weight:bold">&#34;code&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;SUCCESS&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#000;font-weight:bold">}</span>
</span></span></code></pre></div><ul>
<li>输出样例(失败):</li>
</ul>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#204a87;font-weight:bold">&#34;code&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;FAILED&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>  <span style="color:#204a87;font-weight:bold">&#34;data&#34;</span><span style="color:#000;font-weight:bold">:{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;code&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;NOT_FOUND_BIZ&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;message&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;Uninstall biz: test:1.0.0 not found.&#34;</span>
</span></span><span style="display:flex;"><span>  <span style="color:#000;font-weight:bold">}</span>
</span></span><span style="display:flex;"><span><span style="color:#000;font-weight:bold">}</span>
</span></span></code></pre></div><h2 id="switch-a-biz">Switch a biz</h2>
<ul>
<li>URL: 127.0.0.1:1238/switchBiz</li>
<li>输出样例:</li>
</ul>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;bizName&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;dynamic-provider&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;bizVersion&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;1.0.0&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#000;font-weight:bold">}</span>
</span></span></code></pre></div><ul>
<li>输出样例:</li>
</ul>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#204a87;font-weight:bold">&#34;code&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;SUCCESS&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#000;font-weight:bold">}</span>
</span></span></code></pre></div><h2 id="查询所有-biz">查询所有 Biz</h2>
<ul>
<li>URL: 127.0.0.1:1238/queryAllBiz</li>
<li>输入样例:</li>
</ul>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{}</span>
</span></span></code></pre></div><ul>
<li>输出样例:</li>
</ul>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#204a87;font-weight:bold">&#34;code&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;SUCCESS&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>  <span style="color:#204a87;font-weight:bold">&#34;data&#34;</span><span style="color:#000;font-weight:bold">:[</span>
</span></span><span style="display:flex;"><span>    <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&#34;bizName&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;dynamic-provider&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&#34;bizState&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;ACTIVATED&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&#34;bizVersion&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;1.0.0&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&#34;mainClass&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;io.sofastack.dynamic.provider.ProviderApplication&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&#34;webContextPath&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;provider&#34;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#000;font-weight:bold">},</span>
</span></span><span style="display:flex;"><span>    <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&#34;bizName&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;stock-mng&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&#34;bizState&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;ACTIVATED&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&#34;bizVersion&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;1.0.0&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&#34;mainClass&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;embed main&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&#34;webContextPath&#34;</span><span style="color:#000;font-weight:bold">:</span><span style="color:#4e9a06">&#34;/&#34;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#000;font-weight:bold">}</span>
</span></span><span style="display:flex;"><span>  <span style="color:#000;font-weight:bold">]</span>
</span></span><span style="display:flex;"><span><span style="color:#000;font-weight:bold">}</span>
</span></span></code></pre></div><h2 id="查询健康状况">查询健康状况</h2>
<ul>
<li>URL: 127.0.0.1:1238/health</li>
</ul>
<p>以下根据不同的输入参数，获取到不同的状态信息</p>
<h3 id="查询健康状况-1">查询健康状况</h3>
<ul>
<li>输入样例:</li>
</ul>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{}</span>
</span></span></code></pre></div><ul>
<li>输出样例:</li>
</ul>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#204a87;font-weight:bold">&#34;code&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;SUCCESS&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>  <span style="color:#204a87;font-weight:bold">&#34;data&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;healthData&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&#34;jvm&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;max non heap memory(M)&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">-9.5367431640625E-7</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;java version&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;1.8.0_331&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;max memory(M)&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">885.5</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;max heap memory(M)&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">885.5</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;used heap memory(M)&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">137.14127349853516</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;used non heap memory(M)&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">62.54662322998047</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;loaded class count&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">10063</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;init non heap memory(M)&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">2.4375</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;total memory(M)&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">174.5</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;free memory(M)&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">37.358726501464844</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;unload class count&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;total class count&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">10063</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;committed heap memory(M)&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">174.5</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;java home&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;****\\jre&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;init heap memory(M)&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">64.0</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;committed non heap memory(M)&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">66.203125</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;run time(s)&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">34.432</span>
</span></span><span style="display:flex;"><span>      <span style="color:#000;font-weight:bold">},</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&#34;cpu&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;count&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">4</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;total used (%)&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">131749.0</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;type&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;****&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;user used (%)&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">9.926451054656962</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;free (%)&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">81.46475495070172</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;system used (%)&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">6.249762806548817</span>
</span></span><span style="display:flex;"><span>      <span style="color:#000;font-weight:bold">},</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&#34;masterBizInfo&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;webContextPath&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;/&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;bizName&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;bookstore-manager&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;bizState&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;ACTIVATED&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;bizVersion&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;1.0.0&#34;</span>
</span></span><span style="display:flex;"><span>      <span style="color:#000;font-weight:bold">},</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&#34;pluginListInfo&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#000;font-weight:bold">[</span>
</span></span><span style="display:flex;"><span>        <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&#34;artifactId&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;web-ark-plugin&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&#34;groupId&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;com.alipay.sofa&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&#34;pluginActivator&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;com.alipay.sofa.ark.web.embed.WebPluginActivator&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&#34;pluginName&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;web-ark-plugin&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&#34;pluginUrl&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;file:/****/2.2.3-SNAPSHOT/web-ark-plugin-2.2.3-20230901.090402-2.jar!/&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&#34;pluginVersion&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;2.2.3-SNAPSHOT&#34;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#000;font-weight:bold">},</span>
</span></span><span style="display:flex;"><span>        <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&#34;artifactId&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;runtime-sofa-boot-plugin&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&#34;groupId&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;com.alipay.sofa&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&#34;pluginActivator&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;com.alipay.sofa.runtime.ark.plugin.SofaRuntimeActivator&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&#34;pluginName&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;runtime-sofa-boot-plugin&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&#34;pluginUrl&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;file:/****/runtime-sofa-boot-plugin-3.11.0.jar!/&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&#34;pluginVersion&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;3.11.0&#34;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#000;font-weight:bold">}</span>
</span></span><span style="display:flex;"><span>      <span style="color:#000;font-weight:bold">],</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&#34;masterBizHealth&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;readinessState&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;ACCEPTING_TRAFFIC&#34;</span>
</span></span><span style="display:flex;"><span>      <span style="color:#000;font-weight:bold">},</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&#34;bizListInfo&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#000;font-weight:bold">[</span>
</span></span><span style="display:flex;"><span>        <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&#34;bizName&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;bookstore-manager&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&#34;bizState&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;ACTIVATED&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&#34;bizVersion&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;1.0.0&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&#34;webContextPath&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;/&#34;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#000;font-weight:bold">}</span>
</span></span><span style="display:flex;"><span>      <span style="color:#000;font-weight:bold">]</span>
</span></span><span style="display:flex;"><span>    <span style="color:#000;font-weight:bold">}</span>
</span></span><span style="display:flex;"><span>  <span style="color:#000;font-weight:bold">}</span>
</span></span><span style="display:flex;"><span><span style="color:#000;font-weight:bold">}</span>
</span></span></code></pre></div><h3 id="查询系统健康信息">查询系统健康信息</h3>
<ul>
<li>输入样例:</li>
</ul>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#204a87;font-weight:bold">&#34;type&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;system&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>  <span style="color:#8f5902;font-style:italic">// [OPTIONAL] if metrics is null -&gt; query all system health info
</span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span>  <span style="color:#204a87;font-weight:bold">&#34;metrics&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#000;font-weight:bold">[</span><span style="color:#4e9a06">&#34;cpu&#34;</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#4e9a06">&#34;jvm&#34;</span><span style="color:#000;font-weight:bold">]</span>
</span></span><span style="display:flex;"><span><span style="color:#000;font-weight:bold">}</span>
</span></span></code></pre></div><ul>
<li>输出样例:</li>
</ul>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#204a87;font-weight:bold">&#34;code&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;SUCCESS&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>  <span style="color:#204a87;font-weight:bold">&#34;data&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;healthData&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&#34;jvm&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#000;font-weight:bold">{</span><span style="color:#a40000">...</span><span style="color:#000;font-weight:bold">},</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&#34;cpu&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#000;font-weight:bold">{</span><span style="color:#a40000">...</span><span style="color:#000;font-weight:bold">},</span>
</span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic">//      &#34;masterBizHealth&#34;: {...}
</span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span>    <span style="color:#000;font-weight:bold">}</span>
</span></span><span style="display:flex;"><span>  <span style="color:#000;font-weight:bold">}</span>
</span></span><span style="display:flex;"><span><span style="color:#000;font-weight:bold">}</span>
</span></span></code></pre></div><h3 id="查询模块健康信息">查询模块健康信息</h3>
<ul>
<li>输入样例:</li>
</ul>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#204a87;font-weight:bold">&#34;type&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;biz&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>  <span style="color:#8f5902;font-style:italic">// [OPTIONAL] if moduleName is null and moduleVersion is null -&gt; query all biz
</span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span>  <span style="color:#204a87;font-weight:bold">&#34;moduleName&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;bookstore-manager&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>  <span style="color:#8f5902;font-style:italic">// [OPTIONAL] if moduleVersion is null -&gt; query all biz named moduleName
</span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span>  <span style="color:#204a87;font-weight:bold">&#34;moduleVersion&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;1.0.0&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#000;font-weight:bold">}</span>
</span></span></code></pre></div><ul>
<li>输出样例:</li>
</ul>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#204a87;font-weight:bold">&#34;code&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;SUCCESS&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>  <span style="color:#204a87;font-weight:bold">&#34;data&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;healthData&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&#34;bizInfo&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;bizName&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;bookstore-manager&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;bizState&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;ACTIVATED&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;bizVersion&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;1.0.0&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;webContextPath&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;/&#34;</span>
</span></span><span style="display:flex;"><span>      <span style="color:#000;font-weight:bold">}</span>
</span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic">//      &#34;bizListInfo&#34;: [
</span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic">//        {
</span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic">//          &#34;bizName&#34;: &#34;bookstore-manager&#34;,
</span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic">//          &#34;bizState&#34;: &#34;ACTIVATED&#34;,
</span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic">//          &#34;bizVersion&#34;: &#34;1.0.0&#34;,
</span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic">//          &#34;webContextPath&#34;: &#34;/&#34;
</span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic">//        }
</span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic">//      ]
</span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span>    <span style="color:#000;font-weight:bold">}</span>
</span></span><span style="display:flex;"><span>  <span style="color:#000;font-weight:bold">}</span>
</span></span><span style="display:flex;"><span><span style="color:#000;font-weight:bold">}</span>
</span></span></code></pre></div><h3 id="查询插件健康信息">查询插件健康信息</h3>
<ul>
<li>输入样例:</li>
</ul>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#204a87;font-weight:bold">&#34;type&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;plugin&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>  <span style="color:#8f5902;font-style:italic">// [OPTIONAL] if moduleName is null -&gt; query all biz
</span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span>  <span style="color:#204a87;font-weight:bold">&#34;moduleName&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;web-ark-plugin&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#000;font-weight:bold">}</span>
</span></span></code></pre></div><ul>
<li>输出样例:</li>
</ul>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>  <span style="color:#204a87;font-weight:bold">&#34;code&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;SUCCESS&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>  <span style="color:#204a87;font-weight:bold">&#34;data&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;healthData&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>      <span style="color:#204a87;font-weight:bold">&#34;pluginListInfo&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#000;font-weight:bold">[</span>
</span></span><span style="display:flex;"><span>        <span style="color:#000;font-weight:bold">{</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&#34;artifactId&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;web-ark-plugin&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&#34;groupId&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;com.alipay.sofa&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&#34;pluginActivator&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;com.alipay.sofa.ark.web.embed.WebPluginActivator&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&#34;pluginName&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;web-ark-plugin&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&#34;pluginUrl&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;file:/****/web-ark-plugin-2.2.3-20230901.090402-2.jar!/&#34;</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>          <span style="color:#204a87;font-weight:bold">&#34;pluginVersion&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;2.2.3-SNAPSHOT&#34;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#000;font-weight:bold">}</span>
</span></span><span style="display:flex;"><span>      <span style="color:#000;font-weight:bold">]</span>
</span></span><span style="display:flex;"><span>    <span style="color:#000;font-weight:bold">}</span>
</span></span><span style="display:flex;"><span>  <span style="color:#000;font-weight:bold">}</span>
</span></span><span style="display:flex;"><span><span style="color:#000;font-weight:bold">}</span>
</span></span></code></pre></div><h3 id="使用端点查询健康状况">使用端点查询健康状况</h3>
<p>使用端点获取 k8s 模块的健康信息</p>
<p><strong>默认配置</strong></p>
<ul>
<li>端点暴露包括：<code>*</code></li>
<li>端点基本路径：<code>/</code></li>
<li>端点服务器端口：<code>8080</code></li>
</ul>
<p><strong>http 代码结果</strong></p>
<ul>
<li><code>HEALTHY(200)</code>：如果所有健康指标都是健康的，获取健康信息</li>
<li><code>UNHEALTHY(400)</code>：一旦健康指标不健康，获取健康信息</li>
<li><code>ENDPOINT_NOT_FOUND(404)</code>：找不到端点路径或参数</li>
<li><code>ENDPOINT_PROCESS_INTERNAL_ERROR(500)</code>：获取健康过程中抛出错误</li>
</ul>
<h3 id="查询所有健康信息">查询所有健康信息</h3>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span>curl 127.0.0.1:8080/arkletHealth
</span></span></code></pre></div><ul>
<li>输出样例</li>
</ul>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{</span>   
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;healthy&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#204a87;font-weight:bold">true</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;code&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">200</span><span style="color:#000;font-weight:bold">,</span>    
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;codeType&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;HEALTHY&#34;</span><span style="color:#000;font-weight:bold">,</span>    
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&#34;data&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#000;font-weight:bold">{</span>        
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;jvm&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#000;font-weight:bold">{</span><span style="color:#a40000">...</span><span style="color:#000;font-weight:bold">},</span>        
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;masterBizHealth&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#000;font-weight:bold">{</span><span style="color:#a40000">...</span><span style="color:#000;font-weight:bold">},</span>        
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;cpu&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#000;font-weight:bold">{</span><span style="color:#a40000">...</span><span style="color:#000;font-weight:bold">},</span>        
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;masterBizInfo&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#000;font-weight:bold">{</span><span style="color:#a40000">...</span><span style="color:#000;font-weight:bold">},</span>        
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;bizListInfo&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#000;font-weight:bold">[</span><span style="color:#a40000">...</span><span style="color:#000;font-weight:bold">],</span>        
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&#34;pluginListInfo&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#000;font-weight:bold">[</span><span style="color:#a40000">...</span><span style="color:#000;font-weight:bold">]</span>    
</span></span><span style="display:flex;"><span>    <span style="color:#000;font-weight:bold">}</span>
</span></span><span style="display:flex;"><span><span style="color:#000;font-weight:bold">}</span>  
</span></span></code></pre></div><h3 id="查询所有-bizplugin-健康信息">查询所有 biz/plugin 健康信息</h3>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span>curl: 127.0.0.1:8080/arkletHealth/<span style="color:#ce5c00;font-weight:bold">{</span>moduleType<span style="color:#ce5c00;font-weight:bold">}</span> <span style="color:#ce5c00;font-weight:bold">(</span>moduleType 必须在 <span style="color:#ce5c00;font-weight:bold">[</span><span style="color:#4e9a06">&#39;biz&#39;</span>, <span style="color:#4e9a06">&#39;plugin&#39;</span><span style="color:#ce5c00;font-weight:bold">]</span> 中<span style="color:#ce5c00;font-weight:bold">)</span>
</span></span></code></pre></div><ul>
<li>输出样例</li>
</ul>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{</span>   
</span></span><span style="display:flex;"><span>   <span style="color:#204a87;font-weight:bold">&#34;healthy&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#204a87;font-weight:bold">true</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>   <span style="color:#204a87;font-weight:bold">&#34;code&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">200</span><span style="color:#000;font-weight:bold">,</span>    
</span></span><span style="display:flex;"><span>   <span style="color:#204a87;font-weight:bold">&#34;codeType&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;HEALTHY&#34;</span><span style="color:#000;font-weight:bold">,</span>    
</span></span><span style="display:flex;"><span>   <span style="color:#204a87;font-weight:bold">&#34;data&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#000;font-weight:bold">{</span>        
</span></span><span style="display:flex;"><span>       <span style="color:#204a87;font-weight:bold">&#34;bizListInfo&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#000;font-weight:bold">[</span><span style="color:#a40000">...</span><span style="color:#000;font-weight:bold">],</span>  
</span></span><span style="display:flex;"><span>       <span style="color:#8f5902;font-style:italic">// &#34;pluginListInfo&#34;: [...]      
</span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span>   <span style="color:#000;font-weight:bold">}</span>
</span></span><span style="display:flex;"><span><span style="color:#000;font-weight:bold">}</span>  
</span></span></code></pre></div><h3 id="查询单个-bizplugin-健康信息">查询单个 biz/plugin 健康信息</h3>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span>curl 127.0.0.1:8080/arkletHealth/<span style="color:#ce5c00;font-weight:bold">{</span>moduleType<span style="color:#ce5c00;font-weight:bold">}</span>/moduleName/moduleVersion <span style="color:#ce5c00;font-weight:bold">(</span>moduleType must in <span style="color:#ce5c00;font-weight:bold">[</span><span style="color:#4e9a06">&#39;biz&#39;</span>, <span style="color:#4e9a06">&#39;plugin&#39;</span><span style="color:#ce5c00;font-weight:bold">])</span>
</span></span></code></pre></div><ul>
<li>输出样例：</li>
</ul>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-json" data-lang="json"><span style="display:flex;"><span><span style="color:#000;font-weight:bold">{</span>   
</span></span><span style="display:flex;"><span>   <span style="color:#204a87;font-weight:bold">&#34;healthy&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#204a87;font-weight:bold">true</span><span style="color:#000;font-weight:bold">,</span>
</span></span><span style="display:flex;"><span>   <span style="color:#204a87;font-weight:bold">&#34;code&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">200</span><span style="color:#000;font-weight:bold">,</span>    
</span></span><span style="display:flex;"><span>   <span style="color:#204a87;font-weight:bold">&#34;codeType&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;HEALTHY&#34;</span><span style="color:#000;font-weight:bold">,</span>    
</span></span><span style="display:flex;"><span>   <span style="color:#204a87;font-weight:bold">&#34;data&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#000;font-weight:bold">{</span>        
</span></span><span style="display:flex;"><span>       <span style="color:#204a87;font-weight:bold">&#34;bizInfo&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#000;font-weight:bold">{</span><span style="color:#a40000">...</span><span style="color:#000;font-weight:bold">},</span>  
</span></span><span style="display:flex;"><span>       <span style="color:#8f5902;font-style:italic">// &#34;pluginInfo&#34;: {...}      
</span></span></span><span style="display:flex;"><span><span style="color:#8f5902;font-style:italic"></span>   <span style="color:#000;font-weight:bold">}</span>
</span></span><span style="display:flex;"><span><span style="color:#000;font-weight:bold">}</span>
</span></span></code></pre></div><br/>

</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-ca0da12fe622ea86b46a675b1cf7ff9e">5.6.2 - 如何发布 Arklet 版本</h1>
    
	<h3 id="触发-github-action-发布到-snapshot-staging">触发 github Action 发布到 snapshot staging</h3>
<p>版本发布到 maven 中央仓库，发布能力集成到了 github action 里：<br />
<img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1694917403997-feefe1c0-9aff-440c-afca-58f7dce10c19.png#clientId=u0869f56c-af1d-4&amp;from=paste&amp;height=469&amp;id=u1538d344&amp;originHeight=938&amp;originWidth=2114&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=193270&amp;status=done&amp;style=none&amp;taskId=u851fd385-a349-4f24-a37a-ded4c025441&amp;title=&amp;width=1057" alt="image.png"></p>
<p><strong>该 action 需要手动触发执行</strong>：<br />
<img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1694917427074-e50ce7a6-44f7-4f7b-abc8-f78142727b28.png#clientId=u0869f56c-af1d-4&amp;from=paste&amp;height=283&amp;id=u51c5094e&amp;originHeight=566&amp;originWidth=1004&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=55468&amp;status=done&amp;style=none&amp;taskId=u83b68510-dcdd-4dae-9ab1-c1d2d7b34df&amp;title=&amp;width=502" alt="image.png"><br />
执行成功后，只会发布到 snapshot staging，如果是 SNAPSHOT 版本，则这里执行完就可以结束。如果是正式版本，发布到 snapshot staging 之后，还需要推送到 release staging。</p>
<h3 id="发布到-release-staging">发布到 Release staging</h3>
<p>打开  <a href="https://oss.sonatype.org">https://oss.sonatype.org</a> ，点击右上角的 Log In, 登陆信息可找管理员。<br />
点击左侧的 Staging Repositories：<br />
<img src="https://gw.alipayobjects.com/zos/skylark/4f0bacb1-599d-4a3b-90f4-8d88bba2f660/2018/png/d27b8f43-c7eb-41a9-a9c4-49b0308c44d8.png#height=250&amp;id=kxutu&amp;originHeight=431&amp;originWidth=1294&amp;originalType=binary&amp;ratio=1&amp;rotation=0&amp;showTitle=false&amp;status=done&amp;style=none&amp;title=&amp;width=752" alt=""></p>
<p>搜索刚才记录的 ID：<br />
<img src="https://gw.alipayobjects.com/zos/skylark/2c91c79e-fce1-4483-8c35-c712d5367805/2018/png/ae5425f2-a572-4c50-9307-fd9618286689.png#height=394&amp;id=O3wmg&amp;originHeight=749&amp;originWidth=1428&amp;originalType=binary&amp;ratio=1&amp;rotation=0&amp;showTitle=false&amp;status=done&amp;style=none&amp;title=&amp;width=752" alt=""></p>
<p>钩上之后就可以进行 Release (发布) 或者 Drop (放弃) 的操作。</p>
<p><strong>当看不到这两个选项，只有 Close 选项时，则先选择 Close 操作，这时候如果包没有问题，则接下来可以 Release 或者 Drop。如果有问题，下面的内容中的 Activity 中会显示包不能正常 Close 的原因, 按照提示进行修改就可以了。</strong></p>
<h3 id="仓库包同步与搜索">仓库包同步与搜索</h3>
<p>在包发布到 release 仓库之后， 10 分钟后包会更新，在 <a href="http://central.maven.org/maven2/com/alipay/sofa/">http://central.maven.org/maven2/com/alipay/sofa/</a> 能看到包。2 小时之后，可通过 <a href="http://search.maven.org/">搜索</a> 查询到包。</p>
<br/>

</div>



    
	
  

    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-9f7246557f3988e5591410a2c92f379e">5.7 - ModuleController 技术文档</h1>
    
	
</div>



    
      
  
  
  
  

  
  

  
    
    
	
    

<div class="td-content" style="">
    
	<h1 id="pg-72b8455792d08674da639fa21b8e66ae">5.7.1 - ModuleController 架构设计</h1>
    
	<h2 id="介绍">介绍</h2>
<p>ModuleController 是一个 K8S 控制器，该控制器参考 K8S 架构，定义并且实现了 ModuleDeployment、ModuleReplicaSet、Module 等核心模型与调和能力，从而实现了 Serverless 模块的秒级运维调度，以及与基座的联动运维能力。</p>
<h2 id="基本架构">基本架构</h2>
<p>ModuleController 目前包含 ModuleDeployment Opertor、ModuleReplicaSet Operator、Module Operator 三个组件。和 K8S 原生 Deployment 类似，<strong>用户创建 ModuleDeployment 会调和出 ModuleReplicaSet，ModuleReplicaSet 会进一步调和出 Module，最终 Module Operator 会调用 Pod 里的 Arklet SDK 去安装或卸载模块</strong>。此外 ModuleController 还会为 ModuleDeployment 自动生成 K8S Service，企业可以监听该 Service 的 IP 变化实现与自身流量控制系统的集成，从而实现模块粒度的切流和挂流。<br />
<a href="architecture.png"><img src="../architecture.png#from=url&amp;height=536&amp;id=ZnBYG&amp;originHeight=502&amp;originWidth=645&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;status=done&amp;style=none&amp;title=&amp;width=689" alt=""></a></p>
<h2 id="功能清单和-roadmap">功能清单和 RoadMap</h2>
<ul>
<li><strong>08.15：0.2 版本</strong>上线（包括非对等模块发布、卸载、扩缩容、副本保持、基座运维联动）</li>
<li><strong>08.25：0.3 版本</strong>上线（包括回滚链路、各项参数校验、单测达到 80/60、CI 自动化、开发者指南）</li>
<li><strong>09.31：0.5 版本</strong>上线（1:1 先扩后缩、模块回滚、两种调度策略、状态回流、1+ 端到端集成测试）</li>
<li><strong>10.30：0.6 版本</strong>上线（支持以 K8S Service 方式联动企业四七层流量控制、总计 10+ 端到端集成测试）</li>
<li><strong>11.30：1.0 版本</strong>上线（支持对等发布运维、各项修复打磨、总计 20+ 端到端集成测试）</li>
<li><strong>12.30：1.1 版本</strong>上线（支持模块和基座自动弹性伸缩、对等与非对等发布运维能力完善）</li>
</ul>
<br/>

</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-be4b5c4491d910c089a03f3bd6b4ec7b">5.7.2 - CRD 模型设计</h1>
    
	<h2 id="crd-模型对比">CRD 模型对比</h2>
<table>
<thead>
<tr>
<th>K8S 原生 CRD</th>
<th>ModuleController CRD</th>
<th>关系和区别</th>
</tr>
</thead>
<tbody>
<tr>
<td>Pod</td>
<td>Module</td>
<td>Pod：K8S 中创建和管理的、最小的可部署的计算单元。     Module：Serverless 创建和管理的、最小的可部署的计算单元。</td>
</tr>
<tr>
<td>PodSpec</td>
<td>ModuleSpec</td>
<td>PodSpec：对 Pod 的描述。包含容器、调度、卷等。     ModuleSpec：对 Module 的描述，包含模块、服务、调度（亲和性）。</td>
</tr>
<tr>
<td>PodTemplate</td>
<td>ModuleTemplate</td>
<td>PodTemplate：定义 Pod 的生成副本，包含 PodSpec。     ModuleTemplate：定义 Module 的生成副本，包含 ModuleGroupSpec。</td>
</tr>
<tr>
<td>Deployment</td>
<td>ModuleDeployment</td>
<td>Deployment：定义 Pod 的期望状态和副本数量。     ModuleDeployment：定义 Module 的期望状态和副本数量。</td>
</tr>
<tr>
<td>ReplicaSet</td>
<td>ModuleReplicaSet</td>
<td>ReplicaSet：管理 Pod 的运行副本。     <br />ModuleReplicaSet：管理 Module 的运行副本。</td>
</tr>
</tbody>
</table>
<h2 id="moduledeployment-crd-模型">ModuleDeployment CRD 模型</h2>
<p><img src="https://github.com/sofastack/sofa-serverless/assets/13743483/863d8ede-4904-423e-9473-77466af33c46" alt="image"></p>
<h2 id="module-crd-模型">Module CRD 模型</h2>
<p><img src="https://github.com/sofastack/sofa-serverless/assets/13743483/f4e109eb-4b10-4835-a502-7d723b1ca73c" alt="image"></p>
<h2 id="moduletemplate-crd-模型">ModuleTemplate CRD 模型</h2>
<p><img src="https://github.com/sofastack/sofa-serverless/assets/13743483/db4fd36b-d698-4946-8d62-6e6651d3f18a" alt="image"></p>
<h2 id="modulereplicaset-crd-模型">ModuleReplicaSet CRD 模型</h2>
<p><img src="https://github.com/sofastack/sofa-serverless/assets/13743483/13fbf29e-3977-4138-b3dd-849ce871fb3b" alt="image"></p>
<br/>

</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-339ad39102ec6d572f675d168eb0a6c2">5.7.3 - 核心代码结构</h1>
    
	<p><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/671/1694002853387-dfb011bb-b443-401d-b6b2-0e2d89d9ca38.png#clientId=u9331e04a-ec01-4&amp;from=paste&amp;height=733&amp;id=u434d34f6&amp;originHeight=1466&amp;originWidth=2236&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=746447&amp;status=done&amp;style=none&amp;taskId=u60bb866c-f80f-4cda-b668-d41bdef0f7b&amp;title=&amp;width=1118" alt="image.png"></p>
<p><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/671/1694002891414-adf2f622-38ec-46cb-8f73-4ae6efdd87ab.png#clientId=u9331e04a-ec01-4&amp;from=paste&amp;height=107&amp;id=u798a320c&amp;originHeight=214&amp;originWidth=612&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=53871&amp;status=done&amp;style=none&amp;taskId=u47639d5b-c3d6-4356-800a-789e9f2791c&amp;title=&amp;width=306" alt="image.png"></p>
<br/>
<p>核心代码逻辑在 moduledeployment_controller.go、modulereplicaset_controller.go、module_controller.go、controller_utils.go，里面有详细注释。</p>
<br/>
<br/>

</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-de7e40f637d5e11c931b8c9e41910f4d">5.7.4 - 模块生命周期</h1>
    
	<h3 id="模块生命周期">模块生命周期</h3>
<p>4象限描述了模块的生命周期： Prepare、Upgrading、Completed、Available</p>
<p><img src="https://github.com/sofastack/sofa-serverless/assets/13743483/16ec7808-eab9-4293-b9c2-cddda3de5d85" alt="image"></p>
<h3 id="模块状态机">模块状态机</h3>
<p><img src="https://github.com/sofastack/sofa-serverless/assets/13743483/d06c10d6-1d37-48a9-9af3-0d44a6d7e1fd" alt="image"></p>
<br/>

</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-4c6a73428cd292db6a65b7e3740abdd4">5.7.5 - 核心流程时序图</h1>
    
	<h2 id="模块首发">模块首发</h2>
<p><img src="https://github.com/sofastack/sofa-serverless/assets/13743483/d449f851-d989-4221-8809-f39a786529af" alt="image"></p>
<h2 id="模块二发">模块二发</h2>
<p><img src="https://github.com/sofastack/sofa-serverless/assets/13743483/1f649f5e-b8bd-458c-ba9d-333ed1fad46c" alt="image"></p>
<h2 id="模块下线">模块下线</h2>
<p><img src="https://github.com/sofastack/sofa-serverless/assets/13743483/867c16a3-a3a8-4ace-b132-0051bd2ba0ad" alt="image"></p>
<h2 id="对等基座扩容">对等基座扩容</h2>
<p><img src="https://github.com/sofastack/sofa-serverless/assets/13743483/c0db1f13-0ec8-43b4-a24e-7b8677405a15" alt="image"></p>
<h2 id="对等基座缩容">对等基座缩容</h2>
<p><img src="https://github.com/sofastack/sofa-serverless/assets/13743483/7e950729-08dd-4264-aa25-0ddfa6828b79" alt="image">
<br/></p>

</div>



    
	
  

    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-db0fd3436760ca9f36ce5775358861d3">5.8 - Arkctl 技术文档</h1>
    
	
</div>



    
      
  
  
  
  

  
  

  
    
    
	
    

<div class="td-content" style="">
    
	<h1 id="pg-17a1474bf0b4f08b2afd73c908fb081d">5.8.1 - Arkctl 技术文档</h1>
    
	<p>Arkctl 是一个普通 Golang 项目，他是一个命令行工具集，包含了用户在本地开发和运维模块过程中的常用工具，它和普通 Golang 程序开发完全一样，<em>当前初始版本还在开发中</em>。</p>
<br/>

</div>



    
	
  

    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-c5379127fb28ac273198b2c05d133831">5.9 - 多模块运行时适配或最佳实践</h1>
    
	
</div>



    
      
  
  
  
  

  
  

  
    
    
	
    

<div class="td-content" style="">
    
	<h1 id="pg-e8336cb2ec84a57eea63b09a2d517063">5.9.1 - log4j2 的多模块化适配</h1>
    
	<h2 id="为什么需要做适配">为什么需要做适配</h2>
<p>原生 log4j2 在多模块下，模块没有独立打印的日志目录，统一打印到基座目录里，导致日志和对应的监控无法隔离。这里做适配的目的就是要让模块能有独立的日志目录。</p>
<h2 id="普通应用-log4j2-的初始化">普通应用 log4j2 的初始化</h2>
<p>在 Spring 启动前，log4j2 会使用默认值初始化一次各种 logContext 和 Configuration，然后在 Spring 启动过程中，监听 Spring 事件进行初始化
<code>org.springframework.boot.context.logging.LoggingApplicationListener</code>，这里会调用到 Log4j2LoggingSystem.initialize 方法</p>
<p><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1696930949183-9519451c-be76-4d9b-bb6b-28a1b21e7fa7.png" alt=""></p>
<p>该方法会根据 loggerContext 来判断是否已经初始化过了</p>
<blockquote>
<p>这里在多模块下会存在问题一</p>
<p>这里的 getLoggerContext 是根据 org.apache.logging.log4j.LogManager 所在 classLoader 来获取 LoggerContext。根据某个类所在 ClassLoader 来提取 LoggerContext 在多模块化里会存在不稳定，因为模块一些类可以设置为委托给基座加载，所以模块里启动的时候，可能拿到的 LoggerContext 是基座的，导致这里 isAlreadyInitialized 直接返回，导致模块的 log4j2 日志无法进一步根据用户配置文件配置。</p>
</blockquote>
<p>如果没初始化过，则会进入 super.initialize, 这里需要做两部分事情：</p>
<ol>
<li>获取到日志配置文件</li>
<li>解析日志配置文件里的变量值
这两部分在多模块里都可能存在问题，先看下普通应用过程是如何完成这两步的</li>
</ol>
<h3 id="获取日志配置文件">获取日志配置文件</h3>
<p><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1696931678652-81a19dc2-f618-48b0-add3-d098d3781966.png?x-oss-process=image%2Fresize%2Cw_1500%2Climit_0" alt=""></p>
<p>可以看到是通过 ResourceUtils.getURL 获取的 location 对应日志配置文件的 url，这里通过获取到当前线程上下文 ClassLoader 来获取 URL，这在多模块下没有问题（因为每个模块启动时线程上下文已经是 模块自身的 ClassLoader ）。</p>
<p><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1696931908899-f1fac1bb-f365-49f9-81a2-3e2d924c2b7d.png?x-oss-process=image%2Fresize%2Cw_1500%2Climit_0" alt=""></p>
<h3 id="解析日志配置值">解析日志配置值</h3>
<p>配置文件里有一些变量，例如这些变量</p>
<p><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1696932148670-d04bde21-e46b-476c-9cf5-53e43cc4dbe2.png" alt=""></p>
<p>这些变量的解析逻辑在 <code>org.apache.logging.log4j.core.lookup.AbstractLookup</code> 的具体实现里，包括</p>
<table>
<thead>
<tr>
<th></th>
<th>变量写法</th>
<th>代码逻辑地址</th>
</tr>
</thead>
<tbody>
<tr>
<td>${bundle:application:logging.file.path}</td>
<td>org.apache.logging.log4j.core.lookup.ResourceBundleLookup</td>
<td>根据 ResourceBundleLookup 所在 ClassLoader 提前到 application.properties, 读取里面的值</td>
</tr>
<tr>
<td>${ctx:logging.file.path}</td>
<td>org.apache.logging.log4j.core.lookup.ContextMapLookup</td>
<td>根据 LoggerContext 上下文 ThreadContex 存储的值来提起，这里需要提前把 applicaiton.properties 的值设置到 ThreadContext 中</td>
</tr>
</tbody>
</table>
<p>根据上面判断通过 bundle 的方式配置在多模块里不可行，因为 ResourceBundleLookup 可能只存在于基座中，导致始终只能拿到基座的 application.properties，导致模块的日志配置路径与基座相同，模块日志都打到基座中。所以需要改造成使用 ContextMapLookup。</p>
<h2 id="预期多模块合并下的日志">预期多模块合并下的日志</h2>
<p>基座与模块都能使用独立的日志配置、配置值，完全独立。但由于上述分析中，存在两处可能导致模块无法正常初始化的逻辑，故这里需要多 log4j2 进行适配。</p>
<h3 id="多模块适配点">多模块适配点</h3>
<ol>
<li>
<p>getLoggerContext() 能拿到模块自身的 LoggerContext
<img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1696938182575-51ce1066-21f0-47bb-8bdb-c3c7d0814ca3.png" alt=""></p>
</li>
<li>
<p>需要调整成使用 ContextMapLookup，从而模块日志能获取到模块应用名，日志能打印到模块目录里</p>
<p>a. 模块启动时将 application.properties 的值设置到 ThreadContext 中
b. 日志配置时，只能使用 ctx:xxx:xxx 的配置方式</p>
</li>
</ol>
<h2 id="模块改造方式">模块改造方式</h2>
<p><a href="https://github.com/sofastack/sofa-serverless/tree/master/sofa-serverless-runtime/sofa-serverless-adapter-ext/sofa-serverless-adapter-log4j2/src/main/java/com/alipay/sofa/serverless/log4j2">详细查看源码</a></p>

</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-fce299658e201c9a561eaab5974c0199">5.9.2 - ehcache 的多模块化最佳实践</h1>
    
	<h2 id="为什么需要最佳实践">为什么需要最佳实践</h2>
<p>CacheManager 初始化的时候存在共用 static 变量，多应用使用相同的 ehcache name，导致缓存互相覆盖。</p>
<h2 id="最佳实践的几个要求">最佳实践的几个要求</h2>
<ol>
<li>基座里必须引入 ehcache，模块里复用基座</li>
</ol>
<p>在 springboot 里 ehcache 的初始化需要通过 Spring 里定义的 EhCacheCacheConfiguration 来创建，由于 EhCacheCacheConfiguration 是属于 Spring, Spring 统一放在基座里。
<img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1700202934067-7a0d74b7-b765-4c96-ab95-6189602235b8.png#clientId=u4cdbd480-e8bb-4&amp;from=paste&amp;height=679&amp;id=u3a86e2ae&amp;originHeight=1358&amp;originWidth=2284&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=801737&amp;status=done&amp;style=none&amp;taskId=ub2119003-e3dd-4276-83a3-bc0a8598185&amp;title=&amp;width=1142" alt="image.png"></p>
<p>这里在初始化的时候，在做 Bean 初始化的条件判断时会走到类的检验，
<img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1700203147758-c2f4f211-27b1-408a-8a59-04b54a0602f3.png#clientId=u4cdbd480-e8bb-4&amp;from=paste&amp;height=532&amp;id=ea4Xj&amp;originHeight=1064&amp;originWidth=1052&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=607056&amp;status=done&amp;style=none&amp;taskId=u59dc4240-37cd-4a97-8b57-0e71250149b&amp;title=&amp;width=526" alt="image.png">
如果 net.sf.ehcache.CacheManager 是。这里会走到 java native 方法上做判断，从当前类所在的 ClassLoader 里查找 net.sf.ehcache.CacheManager 类，所以基座里必须引入这个依赖，否则会报 ClassNotFound 的错误。
<img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1700203220867-62f2b7be-e853-488c-a6bc-a95c874793f1.png#clientId=u4cdbd480-e8bb-4&amp;from=paste&amp;height=97&amp;id=u3ca967f5&amp;originHeight=194&amp;originWidth=1798&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=104469&amp;status=done&amp;style=none&amp;taskId=u4957f800-31ee-40b3-bb09-487b9ab16ba&amp;title=&amp;width=899" alt="image.png"></p>
<ol start="2">
<li>模块里将引入的 ehcache 排包掉（scope设置成 provide，或者使用自动瘦身能力）</li>
</ol>
<p>模块使用自己 引入的 ehcache，照理可以避免共用基座 CacheManager 类里的 static 变量，而导致报错的问题。但是实际测试发现，模块安装的时候，在初始化 enCacheCacheManager 时，
<img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1700203897715-c9f97922-b466-4e73-8319-1a0f5ec3cc73.png#clientId=u4cdbd480-e8bb-4&amp;from=paste&amp;height=211&amp;id=uaa50406f&amp;originHeight=422&amp;originWidth=2048&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=235120&amp;status=done&amp;style=none&amp;taskId=ub3d92b21-fec0-4462-92ad-91449dcea2d&amp;title=&amp;width=1024" alt="image.png">
<img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1700203915265-f42253e4-1ff4-4088-a87e-8b6e063540ba.png#clientId=u4cdbd480-e8bb-4&amp;from=paste&amp;height=107&amp;id=uedd0a010&amp;originHeight=214&amp;originWidth=1258&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=101140&amp;status=done&amp;style=none&amp;taskId=u044240e0-fe55-4f77-b63e-41ebf9eca47&amp;title=&amp;width=629" alt="image.png">
这里在 new 对象时，需要先获得对象所属类的 CacheManager 是基座的 CacheManager。这里也不能讲 CacheManager 由模块 compile 引入，否则会出现一个类由多个不同 ClassLoader 引入导致的问题。
<img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1700212320690-8112f0f7-7ab7-48a7-8d9d-95aa3d49492a.png#clientId=u4cdbd480-e8bb-4&amp;from=paste&amp;height=145&amp;id=ud90248f9&amp;originHeight=290&amp;originWidth=2736&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=294518&amp;status=done&amp;style=none&amp;taskId=ue9c723ea-0a3b-4854-b069-402238e5fcd&amp;title=&amp;width=1368" alt="image.png"></p>
<p>所以结论是，这里需要全部委托给基座加载。</p>
<h2 id="最佳实践的方式">最佳实践的方式</h2>
<ol>
<li>模块 ehcache 排包瘦身委托给基座加载</li>
<li>如果多个模块里有多个相同的 cacheName，需要修改 cacheName 为不同值。</li>
<li>如果不想改代码的方式修改 cache name，可以通过打包插件的方式动态替换 cacheName</li>
</ol>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-xml" data-lang="xml"><span style="display:flex;"><span> <span style="color:#204a87;font-weight:bold">&lt;plugin&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;groupId&gt;</span>com.google.code.maven-replacer-plugin<span style="color:#204a87;font-weight:bold">&lt;/groupId&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;artifactId&gt;</span>replacer<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;version&gt;</span>1.5.3<span style="color:#204a87;font-weight:bold">&lt;/version&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;executions&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#8f5902;font-style:italic">&lt;!-- 打包前进行替换 --&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;execution&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&lt;phase&gt;</span>prepare-package<span style="color:#204a87;font-weight:bold">&lt;/phase&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&lt;goals&gt;</span>
</span></span><span style="display:flex;"><span>                <span style="color:#204a87;font-weight:bold">&lt;goal&gt;</span>replace<span style="color:#204a87;font-weight:bold">&lt;/goal&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&lt;/goals&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;/execution&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;/executions&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;configuration&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#8f5902;font-style:italic">&lt;!-- 自动识别到项目target文件夹 --&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;basedir&gt;</span>${build.directory}<span style="color:#204a87;font-weight:bold">&lt;/basedir&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#8f5902;font-style:italic">&lt;!-- 替换的文件所在目录规则 --&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;includes&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&lt;include&gt;</span>classes/j2cache/*.properties<span style="color:#204a87;font-weight:bold">&lt;/include&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;/includes&gt;</span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;replacements&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&lt;replacement&gt;</span>
</span></span><span style="display:flex;"><span>                <span style="color:#204a87;font-weight:bold">&lt;token&gt;</span>ehcache.ehcache.name=f6-cache<span style="color:#204a87;font-weight:bold">&lt;/token&gt;</span>
</span></span><span style="display:flex;"><span>                <span style="color:#204a87;font-weight:bold">&lt;value&gt;</span>ehcache.ehcache.name=f6-${parent.artifactId}-cache<span style="color:#204a87;font-weight:bold">&lt;/value&gt;</span>
</span></span><span style="display:flex;"><span>            <span style="color:#204a87;font-weight:bold">&lt;/replacement&gt;</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>        <span style="color:#204a87;font-weight:bold">&lt;/replacements&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;/configuration&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">&lt;/plugin&gt;</span>
</span></span></code></pre></div><ol start="4">
<li>需要把 FactoryBean 的 shared 设置成 false</li>
</ol>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-java" data-lang="java"><span style="display:flex;"><span><span style="color:#5c35cc;font-weight:bold">@Bean</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#204a87;font-weight:bold">public</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">EhCacheManagerFactoryBean</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">ehCacheManagerFactoryBean</span><span style="color:#000;font-weight:bold">()</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000;font-weight:bold">{</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">EhCacheManagerFactoryBean</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">factoryBean</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">new</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">EhCacheManagerFactoryBean</span><span style="color:#000;font-weight:bold">();</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#8f5902;font-style:italic">// 需要把 factoryBean 的 share 属性设置成 false</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">factoryBean</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">setShared</span><span style="color:#000;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">true</span><span style="color:#000;font-weight:bold">);</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#8f5902;font-style:italic">//        factoryBean.setShared(false);</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">factoryBean</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">setCacheManagerName</span><span style="color:#000;font-weight:bold">(</span><span style="color:#4e9a06">&#34;biz1EhcacheCacheManager&#34;</span><span style="color:#000;font-weight:bold">);</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#000">factoryBean</span><span style="color:#000;font-weight:bold">.</span><span style="color:#c4a000">setConfigLocation</span><span style="color:#000;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">new</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">ClassPathResource</span><span style="color:#000;font-weight:bold">(</span><span style="color:#4e9a06">&#34;ehcache.xml&#34;</span><span style="color:#000;font-weight:bold">));</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">        </span><span style="color:#204a87;font-weight:bold">return</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">factoryBean</span><span style="color:#000;font-weight:bold">;</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span><span style="display:flex;"><span><span style="color:#f8f8f8;text-decoration:underline">    </span><span style="color:#000;font-weight:bold">}</span><span style="color:#f8f8f8;text-decoration:underline">
</span></span></span></code></pre></div><p>否则会进入这段逻辑，初始化 CacheManager 的static 变量 instance. 该变量如果有值，且如果模块里 shared 也是ture 的化，就会重新复用 CacheManager 的 instance，从而拿到基座的 CacheManager, 从而报错。
<img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1700360794825-3f7f4a63-22bc-49ea-81d1-83bd94804087.png#clientId=u2481e0c2-f328-4&amp;from=paste&amp;height=399&amp;id=u7432be71&amp;originHeight=798&amp;originWidth=1596&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=422965&amp;status=done&amp;style=none&amp;taskId=u1e450639-4846-4b6a-9862-bac787ae8e5&amp;title=&amp;width=798" alt="image.png">
<img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1700359643422-7b252689-7e0c-41f3-995e-cbc40726136e.png#clientId=u2481e0c2-f328-4&amp;from=paste&amp;height=161&amp;id=u80efa85e&amp;originHeight=322&amp;originWidth=2426&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=339519&amp;status=done&amp;style=none&amp;taskId=u15aeda8f-e089-4bf0-8bc7-e47eff9d2f0&amp;title=&amp;width=1213" alt="image.png"></p>
<h2 id="最佳实践的样例">最佳实践的样例</h2>
<p>样例工程请<a href="https://github.com/sofastack/sofa-serverless/tree/master/samples/springboot-samples/cache/ehcache">参考这里</a></p>

</div>



    
	
  

    
	
  

    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-4588103fb9a692533044ee756a5f863f">6 - 常见 FAQ</h1>
    
	
</div>



    
      
  
  
  
  

  
  

  
    
    
	
    

<div class="td-content" style="">
    
	<h1 id="pg-b0aca01070f80bb35c361f0308eb0170">6.1 - 常见问题列表</h1>
    
	<h4 id="问题-1-1模块-compile-引入-springboot-依赖模块安装时报错">问题 1-1：模块 compile 引入 springboot 依赖，模块安装时报错</h4>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>java.lang.IllegalArgumentException: Cannot instantiate interface org.springframework.context.ApplicationListener : com.alipay.sofa.serverless.common.spring.ServerlessApplicationListener
</span></span></code></pre></div><h5 id="解决方式">解决方式</h5>
<p>模块需要做好瘦身，参考这里：<a href="/docs/tutorials/module-development/module-slimming.md">模块瘦身</a></p>
<h4 id="问题-1-2模块安装找不到-serverlessapplicationlistener">问题 1-2：模块安装找不到 <code>ServerlessApplicationListener</code></h4>
<p>报错信息如下：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>com.alipay.sofa.ark.exception.ArkLoaderException: [ArkBiz Loader] module1:1.0-SNAPSHOT : can not load class: com.alipay.sofa.serverless.common.spring.ServerlessApplicationListener
</span></span></code></pre></div><h5 id="解决方式-1">解决方式</h5>
<p>请在模块里面添加如下依赖：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-xml" data-lang="xml"><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">&lt;dependency&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;groupId&gt;</span>com.alipay.sofa.serverless<span style="color:#204a87;font-weight:bold">&lt;/igroupId&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;artifactId&gt;</span>sofa-serverless-app-starter<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;version&gt;</span>0.5.5<span style="color:#204a87;font-weight:bold">&lt;/version&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">&lt;/dependency&gt;</span>
</span></span></code></pre></div><p>或者升级 sofa-serverless 版本到最新版本</p>
<h4 id="问题-1-3-通过-go-install-无法安装-arkctl">问题 1-3: 通过 go install 无法安装 arkctl</h4>
<p>执行如下命令，报错</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span>go install serverless.alipay.com/sofa-serverless/v1/arkctl@latest
</span></span></code></pre></div><p>报错信息如下：</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-text" data-lang="text"><span style="display:flex;"><span>go: serverless.alipay.com/sofa-serverless/v1/arkctl@latest: module serverless.alipay.com/sofa-serverless/v1/arkctl: Get &#34;https://proxy.golang.org/serverless.alipay.com/sofa-serverless/v1/arkctl/@v/list&#34;: dial tcp 142.251.42.241:443: i/o timeout
</span></span></code></pre></div><h5 id="解决方式-2">解决方式</h5>
<p>arkctl 是作为 sofa-serverless 子目录的方式存在的，所以没法直接 go get，可以从这下面下载执行文件, 请参考<a href="https://github.com/sofastack/sofa-serverless/releases/tag/arkctl-release-0.1.0">安装 arkctl</a></p>
<h4 id="问题-1-4模块安装报-master-biz-environment-is-null">问题 1-4：模块安装报 <code>Master biz environment is null</code></h4>
<p>解决方式，升级 sofa-serverless 版本到最新版本</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-xml" data-lang="xml"><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">&lt;dependency&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;groupId&gt;</span>com.alipay.sofa.serverless<span style="color:#204a87;font-weight:bold">&lt;/igroupId&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;artifactId&gt;</span>sofa-serverless-app-starter<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;version&gt;</span>${最新版本号}<span style="color:#204a87;font-weight:bold">&lt;/version&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">&lt;/dependency&gt;</span>
</span></span></code></pre></div><h4 id="问题-1-5模块静态合并部署无法从制定的目录里找到模块包">问题 1-5：模块静态合并部署无法从制定的目录里找到模块包</h4>
<p>解决方式，升级 sofa-serverless 版本到最新版本</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-xml" data-lang="xml"><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">&lt;dependency&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;groupId&gt;</span>com.alipay.sofa.serverless<span style="color:#204a87;font-weight:bold">&lt;/igroupId&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;artifactId&gt;</span>sofa-serverless-app-starter<span style="color:#204a87;font-weight:bold">&lt;/artifactId&gt;</span>
</span></span><span style="display:flex;"><span>    <span style="color:#204a87;font-weight:bold">&lt;version&gt;</span>${最新版本号}<span style="color:#204a87;font-weight:bold">&lt;/version&gt;</span>
</span></span><span style="display:flex;"><span><span style="color:#204a87;font-weight:bold">&lt;/dependency&gt;</span>
</span></span></code></pre></div>
</div>



    
	
  
    
    
	
    

<div class="td-content" style="page-break-before: always">
    
	<h1 id="pg-d12744cdebcd9160176b435785ebf207">6.2 - 如果模块独立引入 SpringBoot 框架部分会怎样？</h1>
    
	<p>由于多模块运行时的逻辑在基座引入和加载，例如一些 Spring 的 Listener。如果模块启动使用完全自己的 SpringBoot，则会出现一些类的转换或赋值判断失败，例如：</p>
<h2 id="createspringfactoriesinstances">CreateSpringFactoriesInstances</h2>
<p><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1695020207040-788742b8-a1b1-4dc8-8ac2-f0675cf070d5.png#clientId=ufd4bb4ce-38f3-4&amp;from=paste&amp;height=280&amp;id=EvWYQ&amp;originHeight=560&amp;originWidth=2778&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=201445&amp;status=done&amp;style=none&amp;taskId=u342062f0-1d50-4344-9990-2377b42e6ca&amp;title=&amp;width=1389" alt="image.png"></p>
<p>name = &lsquo;com.alipay.sofa.ark.springboot.listener.ArkApplicationStartListener&rsquo;, ClassUtils.forName 获取到的是从基座 ClassLoader 的类<br /><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1695020357927-660e3462-1bd7-4ede-9955-541b63caf650.png#clientId=ufd4bb4ce-38f3-4&amp;from=paste&amp;height=308&amp;id=DwdJg&amp;originHeight=616&amp;originWidth=1786&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=132500&amp;status=done&amp;style=none&amp;taskId=u870534d8-591d-4685-bdef-19aeb287535&amp;title=&amp;width=893" alt="image.png"><br />而 type 是模块启动时加载的，也就是使用模块 BizClassLoader 加载。<br /><img src="https://intranetproxy.alipay.com/skylark/lark/0/2023/png/149473/1695020334793-d8be43cc-b791-4aef-bb75-b8c890cbe82c.png#clientId=ufd4bb4ce-38f3-4&amp;from=paste&amp;height=400&amp;id=q2juJ&amp;originHeight=800&amp;originWidth=1612&amp;originalType=binary&amp;ratio=2&amp;rotation=0&amp;showTitle=false&amp;size=165924&amp;status=done&amp;style=none&amp;taskId=u52077367-d352-49fc-9d49-a6ac0cf539b&amp;title=&amp;width=806" alt="image.png"><br />此时这里做 isAssignable 判断，则会报错。</p>
<div class="highlight"><pre tabindex="0" style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-xml" data-lang="xml"><span style="display:flex;"><span>Cannot instantiate interface org.springframework.context.ApplicationListener : com.alipay.sofa.ark.springboot.listener.ArkApplicationStartListener
</span></span></code></pre></div><p>所以模块框架这部分需要委托给基座加载。</p>
<br/>
<br/>

</div>



    
	
  

    
	
  



          </main>
        </div>
      </div>
      <footer class="td-footer row d-print-none">
  <div class="container-fluid">
    <div class="row mx-md-2">
      <div class="col-6 col-sm-4 text-xs-center order-sm-2">
        
        
        
<ul class="td-footer__links-list">
  
  <li class="td-footer__links-item" data-bs-toggle="tooltip" title="通过社区交流群" aria-label="通过社区交流群">
    <a target="_blank" rel="noopener" href="/docs/contribution-guidelines/communication-channel/" aria-label="通过社区交流群">
      <i class="fab fa-twitter"></i>
    </a>
  </li>
  
</ul>

        
        
      </div>
      <div class="col-6 col-sm-4 text-end text-xs-center order-sm-3">
        
        
        
<ul class="td-footer__links-list">
  
  <li class="td-footer__links-item" data-bs-toggle="tooltip" title="看这里" aria-label="看这里">
    <a target="_blank" rel="noopener" href="/docs/contribution-guidelines/contribution/first-pr/" aria-label="看这里">
      <i class="fab fa-github"></i>
    </a>
  </li>
  
</ul>

        
        
      </div>
      <div class="td-footer__copyright-etc col-12 col-sm-4 text-center py-2 order-sm-2">
        <span>&copy; 2023 SOFAServerless 开源社区 保留所有权利</span>
        
        
      </div>
    </div>
  </div>
</footer>
    </div>
    
  <script src="/js/main.min.1eb4262674b2d02aa8d18559fef13b166dbdfa627fd0a495c66e11577c026aa3.js" integrity="sha256-HrQmJnSy0Cqo0YVZ/vE7Fm29&#43;mJ/0KSVxm4RV3wCaqM=" crossorigin="anonymous"></script>
<script src='/js/prism.js'></script>
<script src='/js/tabpane-persist.js'></script>

  </body>
</html>
